Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not increment NonceManager delta if transaction send fails #4811

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 deletions src.ts/providers/signer-noncemanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ export class NonceManager extends AbstractSigner {
}

async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
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--;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error happens in getNonce, we shouldn't reduce #delta.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore previous comment. The noncePromise is awaited after we increment, so we should always decrease upon error.

throw err;
}
}

signTransaction(tx: TransactionRequest): Promise<string> {
Expand Down