From 6aa12bfb0e5e073a72a946835cdc3e539fa410c0 Mon Sep 17 00:00:00 2001 From: Jake Kidd Date: Wed, 2 Jun 2021 19:06:48 -0700 Subject: [PATCH] handle event where nonce has expired and we are unable to confirm tx --- .../contracts/src.ts/services/ethService.ts | 19 +++++++++++++++++++ modules/types/src/chain.ts | 1 + 2 files changed, 20 insertions(+) diff --git a/modules/contracts/src.ts/services/ethService.ts b/modules/contracts/src.ts/services/ethService.ts index dcd66d3a2..6b7f3c4c9 100644 --- a/modules/contracts/src.ts/services/ethService.ts +++ b/modules/contracts/src.ts/services/ethService.ts @@ -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; @@ -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.", @@ -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 diff --git a/modules/types/src/chain.ts b/modules/types/src/chain.ts index 6048b28be..37a3d11aa 100644 --- a/modules/types/src/chain.ts +++ b/modules/types/src/chain.ts @@ -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