Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #655 from connext/nonce-expired
Browse files Browse the repository at this point in the history
Handle event where nonce is expired and tx is not confirmed
  • Loading branch information
jakekidd authored Jun 9, 2021
2 parents 5d4c087 + 6aa12bf commit 49684b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/contracts/src.ts/services/ethService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export class EthereumChainService extends EthereumChainReader implements IVector
// in this data with the already-existing store record of the tx.
let responses: TransactionResponse[] = [];
let nonce: number | undefined;
let nonceExpired: boolean = false;
let receipt: TransactionReceipt | undefined;
let gasPrice: BigNumber;

Expand Down Expand Up @@ -456,6 +457,7 @@ export class EthereumChainService extends EthereumChainReader implements IVector
// Another ethers message that we could potentially be getting back.
error.message.includes("There is another transaction with same nonce in the queue."))
) {
nonceExpired = true;
this.log.info(
{ method, methodId, channelAddress, reason, nonce, error: error.message },
"Nonce already used: proceeding to check for confirmation in previous transactions.",
Expand All @@ -479,6 +481,23 @@ export class EthereumChainService extends EthereumChainReader implements IVector
} catch (e) {
// Check if the error was a confirmation timeout.
if (e.message === ChainError.reasons.ConfirmationTimeout) {
if (nonceExpired) {
const error = new ChainError(ChainError.reasons.NonceExpired, {
methodId,
method,
});
await this.handleTxFail(
onchainTransactionId,
method,
methodId,
channelAddress,
reason,
receipt,
error,
"Nonce expired and could not confirm tx",
);
return Result.fail(error);
}
// Scale up gas by percentage as specified by GAS_BUMP_PERCENT.
// From ethers docs:
// Generally, the new gas price should be about 50% + 1 wei more, so if a gas price
Expand Down
1 change: 1 addition & 0 deletions modules/types/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class ChainError extends VectorError {
TxReverted: "Transaction reverted on chain",
MaxGasPriceReached: "Max gas price reached",
ConfirmationTimeout: "Timed out waiting for confirmation.",
NonceExpired: "Failed to confirm a tx whose nonce had expired.",
};

// Errors you would see from trying to send a transaction, and
Expand Down

0 comments on commit 49684b9

Please sign in to comment.