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

handle event where nonce has expired and we are unable to confirm tx #646

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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