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

fix: avoid nonce gap in nonceManager (#3142) #3153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xrouss
Copy link

@0xrouss 0xrouss commented Dec 21, 2024

Fixes #3142 by deferring the nonce consumption in prepareTransactionRequest until after gas estimation succeeds, avoiding a nonce gap when gas estimation fails.

Changes

  • Reordered logic so nonceManager.consume(...) is called after gas estimation
  • Added a changeset for a patch release

Details

  • Old behavior: We called nonceManager.consume(...) before gas estimation, so if gas estimation failed, we never broadcast a transaction but had already incremented the nonce.
  • New behavior: We’ve reordered the logic in prepareTransactionRequest so that all fees and gas estimation happen first. Only if those steps succeed do we call consume(...) from the nonce manager. This way, no extra nonce is burned on failure.
  • Alternative considered: Rolling back the nonce in a try/catch: We tested that approach but decided to defer consume entirely until the end, which is simpler and avoids the need for a rollback

Copy link

changeset-bot bot commented Dec 21, 2024

🦋 Changeset detected

Latest commit: ec689f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 21, 2024

@0xrouss is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nonceManager still incrementing if tx was not sent (estimateGas failure)
1 participant