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

Problem with nonce increment in NonceManager #3812

Closed
adetante opened this issue Feb 22, 2023 · 2 comments
Closed

Problem with nonce increment in NonceManager #3812

adetante opened this issue Feb 22, 2023 · 2 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@adetante
Copy link

Describe the Feature

I think there is a problem with the NonceManager.getNonce function in v6, which causes a general increment of the nonce:

async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse> {
  const noncePromise = this.getNonce("pending");
  this.increment();

  tx = await this.signer.populateTransaction(tx);
  tx.nonce = await noncePromise; // nonce has already been incremented!

  // ...
}

async getNonce(blockTag?: BlockTag): Promise<number> {
  if (blockTag === "pending") {
     if (this.#noncePromise == null) {
       this.#noncePromise = super.getNonce("pending");
      }
      return (await this.#noncePromise) + this.#delta;
    }

    return super.getNonce(blockTag);
}

increment(): void {
  this.#delta++;
}

v5 used a temporary variable captured in the lambda: https://github.com/ethers-io/ethers.js/blob/v5.7.2/packages/experimental/src.ts/nonce-manager.ts#L34

Code Example

No response

@adetante adetante added the enhancement New feature or improvement. label Feb 22, 2023
@adetante
Copy link
Author

Here is my PR: #3813

@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6 labels Feb 22, 2023
@ricmoo
Copy link
Member

ricmoo commented Feb 23, 2023

Should be fixed in v6.0.6. Try it out and let me know.

Thanks! :)

@ricmoo ricmoo closed this as completed Feb 23, 2023
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Feb 23, 2023
dbcfd added a commit to ceramicnetwork/ceramic-anchor-service that referenced this issue Apr 4, 2023
Per ethers-io/ethers.js#3812, nonce may be
incorrectly incremented, which can produce off by one errors which
we are currently seeing in QA and Clay
dbcfd added a commit to ceramicnetwork/ceramic-anchor-service that referenced this issue Apr 5, 2023
Per ethers-io/ethers.js#3812, nonce may be
incorrectly incremented, which can produce off by one errors which
we are currently seeing in QA and Clay
dbcfd added a commit to ceramicnetwork/ceramic-anchor-service that referenced this issue Apr 6, 2023
Per ethers-io/ethers.js#3812, nonce may be
incorrectly incremented, which can produce off by one errors which
we are currently seeing in QA and Clay
dbcfd added a commit to ceramicnetwork/ceramic-anchor-service that referenced this issue Apr 13, 2023
Per ethers-io/ethers.js#3812, nonce may be
incorrectly incremented, which can produce off by one errors which
we are currently seeing in QA and Clay
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants