From a3b1e37888bfc08a77d7d2757b4a88a8823472fa Mon Sep 17 00:00:00 2001 From: wille Date: Wed, 21 Aug 2024 09:35:07 +0200 Subject: [PATCH] Do not increment NonceManager delta if transaction send fails --- src.ts/providers/signer-noncemanager.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src.ts/providers/signer-noncemanager.ts b/src.ts/providers/signer-noncemanager.ts index 724bfe89ed..fae5445bb5 100644 --- a/src.ts/providers/signer-noncemanager.ts +++ b/src.ts/providers/signer-noncemanager.ts @@ -73,15 +73,18 @@ export class NonceManager extends AbstractSigner { } async sendTransaction(tx: TransactionRequest): Promise { - const noncePromise = this.getNonce("pending"); - this.increment(); + try { + const noncePromise = this.getNonce("pending"); + this.increment(); - tx = await this.signer.populateTransaction(tx); - tx.nonce = await noncePromise; + tx = await this.signer.populateTransaction(tx); + tx.nonce = await noncePromise; - // @TODO: Maybe handle interesting/recoverable errors? - // Like don't increment if the tx was certainly not sent - return await this.signer.sendTransaction(tx); + return await this.signer.sendTransaction(tx); + } catch (err) { + this.#delta--; + throw err; + } } signTransaction(tx: TransactionRequest): Promise {