Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
7dd0134
stop waiting after `transactionBlockTimeout`
Muhammad-Altabba Jul 28, 2022
d5e4efb
add `transactionRpcTimeou` and implement related logic
Muhammad-Altabba Aug 3, 2022
94fe864
remove a testing variable
Muhammad-Altabba Aug 3, 2022
67b7e4f
fixed typos and re-arranged json
Muhammad-Altabba Aug 4, 2022
635ff8e
few comments edits and tiny enhancements
Muhammad-Altabba Aug 4, 2022
2fe7ff1
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Aug 4, 2022
6dd9b5c
Merge branch '4.x' into fix/5293/interrupt-waiting-for-node-after-tim…
Muhammad-Altabba Aug 4, 2022
9010022
handle different timeout errors for different providers when nonce is…
Muhammad-Altabba Aug 4, 2022
1e9d2d2
rename transactionRpcTimeout to transactionSendTimeout
Muhammad-Altabba Aug 4, 2022
ee618fe
fix an issue inside transactionPollingTimeout at waitForTransactionRe…
Muhammad-Altabba Aug 4, 2022
df6b7c4
Merge branch 'fix/5293/interrupt-waiting-for-node-after-timeout' of h…
Muhammad-Altabba Aug 4, 2022
b720f85
resolve an issue in a test case with transactionPollingTimeout
Muhammad-Altabba Aug 4, 2022
e4e74bf
increase transactionPollingTimeout at some tests
Muhammad-Altabba Aug 4, 2022
373418a
fix a config at a test
Muhammad-Altabba Aug 4, 2022
91e2db2
clare timeout at waitWithTimeout
Muhammad-Altabba Aug 10, 2022
afc6c8d
refactor the code for `waitForTransactionReceipt`
Muhammad-Altabba Aug 10, 2022
5c41d40
Merge remote-tracking branch 'origin/4.x' into fix/5293/interrupt-wai…
Muhammad-Altabba Aug 10, 2022
ca960de
decrease transactionPollingTimeout config at a test case
Muhammad-Altabba Aug 10, 2022
8514511
Merge branch '4.x' into fix/5293/interrupt-waiting-for-node-after-tim…
Muhammad-Altabba Aug 10, 2022
11d6396
increase `transactionSendTimeout` to 1 min
Muhammad-Altabba Aug 10, 2022
4efe05f
Merge branch 'fix/5293/interrupt-waiting-for-node-after-timeout' of h…
Muhammad-Altabba Aug 10, 2022
defdfb7
inclease `transactionSendTimeout` to 750 seconds (12.5 min)
Muhammad-Altabba Aug 10, 2022
c12510b
fix a test case by updating a config comparison value
Muhammad-Altabba Aug 10, 2022
612e5b1
updating comment and whitespaces
Muhammad-Altabba Aug 10, 2022
1274bd6
update unit tests accoding to the latest refactor of `WaitForTransact…
Muhammad-Altabba Aug 11, 2022
f99dd40
call `Error.captureStackTrace(...)` only if available
Muhammad-Altabba Aug 11, 2022
aff34a6
Merge branch '4.x' into fix/5293/interrupt-waiting-for-node-after-tim…
Muhammad-Altabba Aug 11, 2022
3c3331e
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Aug 11, 2022
bd4e535
Merge branch '4.x' into fix/5293/interrupt-waiting-for-node-after-tim…
Muhammad-Altabba Aug 11, 2022
9a3573a
Merge remote-tracking branch 'origin/4.x' into fix/5293/interrupt-wai…
Muhammad-Altabba Aug 12, 2022
3226dfe
updating a comment at an integration est
Muhammad-Altabba Aug 12, 2022
ed6a629
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Aug 12, 2022
6f84799
Merge branch 'feature/5113/stop-waiting-after-transactionBlockTimeout…
Muhammad-Altabba Aug 12, 2022
74a12c2
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Aug 17, 2022
8d12305
Merge branch '4.x' into fix/5293/interrupt-waiting-for-node-after-tim…
Muhammad-Altabba Aug 17, 2022
80bb971
Merge branch 'fix/5293/interrupt-waiting-for-node-after-timeout' into…
Muhammad-Altabba Aug 18, 2022
56d0af8
small fixes for TransactionBlockTimeout
Muhammad-Altabba Aug 18, 2022
89f9f7a
improve test for transactionBlockTimeout
Muhammad-Altabba Aug 18, 2022
6bd2aeb
apply a fix at a test for transactionBlockTimeout
Muhammad-Altabba Aug 18, 2022
0c98339
update a timeout at test for faster run
Muhammad-Altabba Aug 18, 2022
d0c4794
Apply suggestions from code review
Muhammad-Altabba Aug 18, 2022
bfe1e5a
Update packages/web3-eth/src/errors.ts
Muhammad-Altabba Aug 18, 2022
28ac55e
add a missing import
Muhammad-Altabba Aug 18, 2022
1d261c9
Merge branch 'fix/5293/interrupt-waiting-for-node-after-timeout' into…
Muhammad-Altabba Aug 18, 2022
3a64910
improve a test case for `transactionBlockTimeout`
Muhammad-Altabba Aug 18, 2022
1ead018
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Aug 18, 2022
7613844
handle an edge case at at test for transactionBlockTimeout
Muhammad-Altabba Aug 18, 2022
31e2ad5
speedup a test case for transactionBlockTimeout
Muhammad-Altabba Aug 18, 2022
04b6bf4
tolerate when checking an error message at web3-eth
Muhammad-Altabba Aug 18, 2022
f9e4cec
Apply BlockTimeout to sendTansaction
Muhammad-Altabba Aug 20, 2022
87a03ef
fix unit test at web3-eth according to the new structure
Muhammad-Altabba Aug 21, 2022
f6547ee
fix a docusaurus syntax complain
Muhammad-Altabba Aug 21, 2022
f660e8c
try increasing the web3-eth integration test timeout
Muhammad-Altabba Aug 21, 2022
74207ad
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Aug 25, 2022
b174271
try handling promise rejection in one test in a different way because…
Muhammad-Altabba Aug 25, 2022
c4ab371
add a missed `return` after `reject` at `sendTransaction`
Muhammad-Altabba Aug 25, 2022
7a35976
tiny fix and tries for an issue in the pipeline
Muhammad-Altabba Aug 25, 2022
f367433
try sending more transactions to enforce composing more block for an …
Muhammad-Altabba Aug 25, 2022
9e48309
try for an issue in the pipeline: do not wait for the receipt when te…
Muhammad-Altabba Aug 25, 2022
6e93da0
revert some un-needed changes in test helper
Muhammad-Altabba Aug 25, 2022
5eafd42
revert an update to a jest timeout
Muhammad-Altabba Aug 25, 2022
d3491c3
try for an issue in the pipeline
Muhammad-Altabba Aug 25, 2022
ae3da4a
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Aug 25, 2022
a4b588c
try for an issue in the pipeline
Muhammad-Altabba Aug 25, 2022
39821cc
try for an issue in the pipeline
Muhammad-Altabba Aug 25, 2022
28d300d
try for an issue in the pipeline
Muhammad-Altabba Aug 25, 2022
4ffdf46
a try for an issue in the pipeline
Muhammad-Altabba Aug 29, 2022
4a598a3
a try for an issue in the pipeline
Muhammad-Altabba Aug 29, 2022
4e67f51
a try for an issue in the pipeline
Muhammad-Altabba Aug 29, 2022
90cebf4
a try for an issue in the pipeline
Muhammad-Altabba Aug 29, 2022
fe4cddd
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Aug 29, 2022
1dbcaa6
a tiny fix after merge
Muhammad-Altabba Aug 29, 2022
2dcfded
enhance a test case at web3-eth integration test
Muhammad-Altabba Aug 29, 2022
476077d
enhance a test case at web3-eth integration test
Muhammad-Altabba Aug 29, 2022
d555dc0
enhance a test case at web3-eth integration test
Muhammad-Altabba Aug 29, 2022
2eace84
enhance a test case at web3-eth integration test
Muhammad-Altabba Aug 29, 2022
51abd5c
fix a test case at web3-eth integration default.test.ts
Muhammad-Altabba Sep 1, 2022
c702cc0
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Sep 1, 2022
8df6ba1
add removeAllListeners after finish testing ''watch polling transacti…
Muhammad-Altabba Sep 1, 2022
c17481b
add a warn if connection raises an error while closing
Muhammad-Altabba Sep 1, 2022
4303c1d
tiny fix and improvements to tests at web-eth
Muhammad-Altabba Sep 1, 2022
6183d28
tiny fix for a test warning at web-eth
Muhammad-Altabba Sep 1, 2022
279aed2
revert un needed changes
Muhammad-Altabba Sep 1, 2022
fd17f20
enhance a test case at web3-eth
Muhammad-Altabba Sep 1, 2022
d38ef68
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Sep 1, 2022
dbeab7a
wait a bit to ensure a new block at a test case in web3-eth
Muhammad-Altabba Sep 5, 2022
c25b102
Merge branch 'feature/5113/stop-waiting-after-transactionBlockTimeout…
Muhammad-Altabba Sep 5, 2022
d5db7d3
tiny enhancement at a test case in web3-eth
Muhammad-Altabba Sep 5, 2022
f75014d
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
45eec68
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
3a0805f
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
337fe80
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
566f609
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
9142d08
add few temp console logging
Muhammad-Altabba Sep 6, 2022
1c2b4de
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Sep 6, 2022
e24032f
add few temp console logging
Muhammad-Altabba Sep 6, 2022
bd7d191
Merge branch 'feature/5113/stop-waiting-after-transactionBlockTimeout…
Muhammad-Altabba Sep 6, 2022
aea8a32
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
1a2fd46
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
8433d3e
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
b0e271c
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
ba2a4a1
try for an issue in the pipeline
Muhammad-Altabba Sep 6, 2022
ac98e10
tiny code cleaning
Muhammad-Altabba Sep 6, 2022
28d79d2
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
71850a9
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
7c831fa
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
bca5e6f
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
0ff1573
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
6d3138a
tiny fix for a typing mismatch
Muhammad-Altabba Sep 7, 2022
c729654
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
ef782bd
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
043cca5
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
3270fc4
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
e9a29eb
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
d79f880
try for an issue in the pipeline
Muhammad-Altabba Sep 7, 2022
bbf5284
Wait a bit before closing a connection
Muhammad-Altabba Sep 7, 2022
dbdfe1e
tiny touch for tests at web3-eth
Muhammad-Altabba Sep 7, 2022
045ada6
Add function comment
Muhammad-Altabba Sep 8, 2022
7af5f77
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
Muhammad-Altabba Sep 9, 2022
bce6b05
Apply suggestions from code review
Muhammad-Altabba Sep 10, 2022
688fa46
move errors.ts from webs-eth to webb3-errors
Muhammad-Altabba Sep 10, 2022
ceee9aa
Merge branch 'feature/5113/stop-waiting-after-transactionBlockTimeout…
Muhammad-Altabba Sep 10, 2022
2cce357
Merge branch '4.x' into feature/5113/stop-waiting-after-transactionBl…
jdevcs Sep 13, 2022
abad14e
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Sep 20, 2022
261007f
fix an issue in the usage of 2 error codes
Muhammad-Altabba Sep 20, 2022
3a3b28e
log for an error in the pipeline
Muhammad-Altabba Sep 20, 2022
fe113b2
log for an error in the pipeline
Muhammad-Altabba Sep 20, 2022
3c07dd6
log for an error in the pipeline
Muhammad-Altabba Sep 20, 2022
c801202
try for an issue in the pipe line
Muhammad-Altabba Sep 20, 2022
1c08018
improve `rejectIfConditionAtInterval`
Muhammad-Altabba Sep 20, 2022
d5432ac
cause pollTillDefined to stop once found
Muhammad-Altabba Sep 20, 2022
e826ee9
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Sep 21, 2022
42086cc
catch and log errors when pooling for new blocks or transaction receipts
Muhammad-Altabba Sep 21, 2022
964f00a
Merge remote-tracking branch 'origin/4.x' into feature/5113/stop-wait…
Muhammad-Altabba Sep 22, 2022
11cc08d
update CHANGELOG.md files
Muhammad-Altabba Sep 22, 2022
6c3139f
update CHANGELOG.md
Muhammad-Altabba Sep 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ should use 4.0.1-alpha.0 for testing.
- Added the error code `ERR_TX_GAS_MISMATCH` and used it inside `TransactionGasMismatchError` (#5462)
- Added `SignatureError` to `web3-errors/src/errors/signature_errors.ts` (moved from `web3-eth/src/errors.ts`) (#5462)
- Added the errors' classes to `web3-errors/src/errors/transaction_errors.ts` from `web3-eth/src/errors.ts` (#5462)
- Added `TransactionBlockTimeoutError` class and its error code `ERR_TX_BLOCK_TIMEOUT` (#5294)

#### web3-eth

- [setimmediate](https://github.com/yuzujs/setImmediate) package to polyfill [setImmediate](https://nodejs.org/api/timers.html#setimmediatecallback-args) for browsers (#5450)
- Implemented the logic for `transactionBlockTimeout` (#5294)

#### web3-eth-abi

Expand All @@ -759,6 +765,10 @@ should use 4.0.1-alpha.0 for testing.
- Decoding error data, using Error ABI if available, according to EIP-838. (#5434)
- The class `Web3ContractError` is moved from this package to `web3-error`. (#5434)

#### web3-utils

- Added and exported three reusable utility functions: `pollTillDefined`, `rejectIfTimeout` and `rejectIfConditionAtInterval` which are useful when dealing with promises that involves polling, rejecting after timeout or rejecting if a condition was met when calling repeatably at every time intervals.

### Changed

#### web3-error
Expand Down
1 change: 1 addition & 0 deletions packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added the error code `ERR_TX_GAS_MISMATCH` and used it inside `TransactionGasMismatchError` (#5462)
- Added `SignatureError` to `web3-errors/src/errors/signature_errors.ts` (moved from `web3-eth/src/errors.ts`) (#5462)
- Added the errors' classes to `web3-errors/src/errors/transaction_errors.ts` from `web3-eth/src/errors.ts` (#5462)
- Added `TransactionBlockTimeoutError` class and its error code `ERR_TX_BLOCK_TIMEOUT` (#5294)

### Changed

Expand Down
1 change: 1 addition & 0 deletions packages/web3-errors/src/error_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const ERR_TX_LOCAL_WALLET_NOT_AVAILABLE = 429;

export const ERR_TX_NOT_FOUND = 430;
export const ERR_TX_SEND_TIMEOUT = 431;
export const ERR_TX_BLOCK_TIMEOUT = 432;

export const ERR_TX_SIGNING = 433;
export const ERR_TX_GAS_MISMATCH = 434;
Expand Down
26 changes: 22 additions & 4 deletions packages/web3-errors/src/errors/transaction_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Bytes, HexString, Numbers, TransactionReceipt } from 'web3-types';
import {
ERR_RAW_TX_UNDEFINED,
ERR_TX,
ERR_TX_BLOCK_TIMEOUT,
ERR_TX_CONTRACT_NOT_STORED,
ERR_TX_CHAIN_ID_MISMATCH,
ERR_TX_DATA_AND_INPUT,
Expand All @@ -40,19 +41,19 @@ import {
ERR_TX_MISSING_CUSTOM_CHAIN_ID,
ERR_TX_MISSING_GAS,
ERR_TX_NO_CONTRACT_ADDRESS,
ERR_TX_NOT_FOUND,
ERR_TX_OUT_OF_GAS,
ERR_TX_POLLING_TIMEOUT,
ERR_TX_RECEIPT_MISSING_BLOCK_NUMBER,
ERR_TX_RECEIPT_MISSING_OR_BLOCKHASH_NULL,
ERR_TX_REVERT_INSTRUCTION,
ERR_TX_REVERT_TRANSACTION,
ERR_TX_REVERT_WITHOUT_REASON,
ERR_TX_NOT_FOUND,
ERR_TX_SEND_TIMEOUT,
ERR_TX_SIGNING,
ERR_TX_UNABLE_TO_POPULATE_NONCE,
ERR_TX_UNSUPPORTED_EIP_1559,
ERR_TX_UNSUPPORTED_TYPE,
ERR_TX_POLLING_TIMEOUT,
ERR_TX_RECEIPT_MISSING_OR_BLOCKHASH_NULL,
ERR_TX_RECEIPT_MISSING_BLOCK_NUMBER,
} from '../error_codes';
import { InvalidValueError, Web3Error } from '../web3_error_base';

Expand Down Expand Up @@ -157,6 +158,7 @@ export class TransactionNotFound extends TransactionError {
this.code = ERR_TX_NOT_FOUND;
}
}

export class InvalidTransactionWithSender extends InvalidValueError {
public code = ERR_TX_INVALID_SENDER;

Expand Down Expand Up @@ -410,6 +412,22 @@ export class TransactionPollingTimeoutError extends Web3Error {
}
}

export class TransactionBlockTimeoutError extends Web3Error {
public code = ERR_TX_BLOCK_TIMEOUT;

public constructor(value: {
starterBlockNumber: number;
numberOfBlocks: number;
transactionHash?: Bytes;
}) {
super(
`Transaction started at ${value.starterBlockNumber} but was not mined within ${
value.numberOfBlocks
} blocks. ${transactionTimeoutHint(value.transactionHash)}`,
);
}
}

export class TransactionMissingReceiptOrBlockHashError extends InvalidValueError {
public code = ERR_TX_RECEIPT_MISSING_OR_BLOCKHASH_NULL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
createAccount,
createNewAccount,
createTempAccount,
closeOpenConnection
closeOpenConnection,
} from '../fixtures/system_test_utils';

describe('personal integration tests', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- [setimmediate](https://github.com/yuzujs/setImmediate) package to polyfill [setImmediate](https://nodejs.org/api/timers.html#setimmediatecallback-args) for browsers (#5450)
- Implemented the logic for `transactionBlockTimeout` (#5294)

### Removed

Expand Down
67 changes: 30 additions & 37 deletions packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,11 @@ import {
TransactionWithLocalWalletIndex,
} from 'web3-types';
import { Web3Context, Web3PromiEvent } from 'web3-core';
import {
ETH_DATA_FORMAT,
FormatType,
DataFormat,
DEFAULT_RETURN_FORMAT,
format,
waitWithTimeout,
} from 'web3-utils';
import { ETH_DATA_FORMAT, FormatType, DataFormat, DEFAULT_RETURN_FORMAT, format } from 'web3-utils';
import { isBlockTag, isBytes, isNullish, isString } from 'web3-validator';
import {
TransactionError,
TransactionRevertError,
SignatureError,
TransactionSendTimeoutError,
} from 'web3-errors';
import { SignatureError, TransactionError, TransactionRevertError } from 'web3-errors';

import { decodeSignedTransaction } from './utils/decode_signed_transaction';
import * as rpcMethods from './rpc_methods';
import {
accountSchema,
Expand All @@ -77,11 +67,12 @@ import { formatTransaction } from './utils/format_transaction';
// eslint-disable-next-line import/no-cycle
import { getTransactionGasPricing } from './utils/get_transaction_gas_pricing';
// eslint-disable-next-line import/no-cycle
import { trySendTransaction } from './utils/try_send_transaction';
// eslint-disable-next-line import/no-cycle
import { waitForTransactionReceipt } from './utils/wait_for_transaction_receipt';
import { watchTransactionForConfirmations } from './utils/watch_transaction_for_confirmations';
import { Web3EthExecutionAPI } from './web3_eth_execution_api';
import { NUMBER_DATA_FORMAT } from './constants';
import { decodeSignedTransaction } from './utils/decode_signed_transaction';

/**
*
Expand Down Expand Up @@ -1119,27 +1110,23 @@ export function sendTransaction<
transactionFormatted as Record<string, unknown>,
);

transactionHash = await waitWithTimeout(
rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransaction.rawTransaction,
),
web3Context.transactionSendTimeout,
new TransactionSendTimeoutError({
numberOfSeconds: web3Context.transactionSendTimeout / 1000,
transactionHash: signedTransaction.transactionHash,
}),
transactionHash = await trySendTransaction(
web3Context,
async (): Promise<string> =>
rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransaction.rawTransaction,
),
signedTransaction.transactionHash,
);
} else {
transactionHash = await waitWithTimeout(
rpcMethods.sendTransaction(
web3Context.requestManager,
transactionFormatted as Partial<TransactionWithSenderAPI>,
),
web3Context.transactionSendTimeout,
new TransactionSendTimeoutError({
numberOfSeconds: web3Context.transactionSendTimeout / 1000,
}),
transactionHash = await trySendTransaction(
web3Context,
async (): Promise<string> =>
rpcMethods.sendTransaction(
web3Context.requestManager,
transactionFormatted as Partial<TransactionWithSenderAPI>,
),
);
}

Expand Down Expand Up @@ -1190,6 +1177,7 @@ export function sendTransaction<
);
}
reject(transactionReceiptFormatted as unknown as ResolveType);
return;
} else {
resolve(transactionReceiptFormatted as unknown as ResolveType);
}
Expand Down Expand Up @@ -1340,9 +1328,13 @@ export function sendSignedTransaction<
// await getRevertReason(web3Context, transaction, returnFormat);
// }

const transactionHash = await rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransactionFormattedHex,
const transactionHash = await trySendTransaction(
web3Context,
async (): Promise<string> =>
rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransactionFormattedHex,
),
);

if (promiEvent.listenerCount('sent') > 0) {
Expand Down Expand Up @@ -1392,6 +1384,7 @@ export function sendSignedTransaction<
);
}
reject(transactionReceiptFormatted as unknown as ResolveType);
return;
} else {
resolve(transactionReceiptFormatted as unknown as ResolveType);
}
Expand Down
53 changes: 53 additions & 0 deletions packages/web3-eth/src/utils/reject_if_block_timeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { EthExecutionAPI, Bytes } from 'web3-types';
import { Web3Context } from 'web3-core';
import { rejectIfConditionAtInterval } from 'web3-utils';

import { TransactionBlockTimeoutError } from 'web3-errors';
import { NUMBER_DATA_FORMAT } from '../constants';
// eslint-disable-next-line import/no-cycle
import { getBlockNumber } from '../rpc_method_wrappers';

/* TODO: After merge, there will be constant block mining time (exactly 12 second each block, except slot missed that currently happens in <1% of slots. ) so we can optimize following function
for POS NWs, we can skip checking getBlockNumber(); after interval and calculate only based on time that certain num of blocked are mined after that for internal double check, can do one getBlockNumber() call and timeout.
*/
export function rejectIfBlockTimeout(
web3Context: Web3Context<EthExecutionAPI>,
starterBlockNumber: number,
interval: number,
transactionHash?: Bytes,
): [NodeJS.Timer, Promise<never>] {
return rejectIfConditionAtInterval(async () => {
let lastBlockNumber;
try {
lastBlockNumber = await getBlockNumber(web3Context, NUMBER_DATA_FORMAT);
} catch (error) {
console.warn('An error happen while trying to get the block number', error);
return undefined;
}
const numberOfBlocks = lastBlockNumber - starterBlockNumber;
if (numberOfBlocks >= web3Context.transactionBlockTimeout) {
return new TransactionBlockTimeoutError({
starterBlockNumber,
numberOfBlocks,
transactionHash,
});
}
return undefined;
}, interval);
}
64 changes: 64 additions & 0 deletions packages/web3-eth/src/utils/try_send_transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { Web3Context } from 'web3-core';
import { EthExecutionAPI, Bytes } from 'web3-types';
import { AsyncFunction, rejectIfTimeout } from 'web3-utils';

import { TransactionSendTimeoutError } from 'web3-errors';
import { NUMBER_DATA_FORMAT } from '../constants';
// eslint-disable-next-line import/no-cycle
import { rejectIfBlockTimeout } from './reject_if_block_timeout';
// eslint-disable-next-line import/no-cycle
import { getBlockNumber } from '../rpc_method_wrappers';

/**
* An internal function to send a transaction or throws if sending did not finish during the timeout during the blocks-timeout.
* @param web3Context the context to read the configurations from
* @param sendTransactionFunc the function that will send the transaction (could be sendTransaction or sendRawTransaction)
* @param transactionHash to be used inside the exception message if there will be any exceptions.
* @returns the Promise<string> returned by the `sendTransactionFunc`.
*/
export async function trySendTransaction(
web3Context: Web3Context<EthExecutionAPI>,
sendTransactionFunc: AsyncFunction<string>,
transactionHash?: Bytes,
): Promise<string> {
const pollingInterval = web3Context.transactionPollingInterval;

const [timeoutId, rejectOnTimeout] = rejectIfTimeout(
web3Context.transactionSendTimeout,
new TransactionSendTimeoutError({
numberOfSeconds: web3Context.transactionSendTimeout / 1000,
transactionHash,
}),
);

const starterBlockNumber = await getBlockNumber(web3Context, NUMBER_DATA_FORMAT);
const [intervalId, rejectOnBlockTimeout] = rejectIfBlockTimeout(
web3Context,
starterBlockNumber,
pollingInterval,
transactionHash,
);

try {
return await Promise.race([sendTransactionFunc(), rejectOnTimeout, rejectOnBlockTimeout]);
} finally {
clearTimeout(timeoutId);
clearInterval(intervalId);
}
}
Loading