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

nonceManager still incrementing if tx was not sent (estimateGas failure) #3142

Open
1 task done
nmalzieu opened this issue Dec 18, 2024 · 1 comment · May be fixed by #3153
Open
1 task done

nonceManager still incrementing if tx was not sent (estimateGas failure) #3142

nmalzieu opened this issue Dec 18, 2024 · 1 comment · May be fixed by #3153
Labels
Good First Issue Misc: Good First Issue

Comments

@nmalzieu
Copy link

Check existing issues

Viem Version

2.21.53

Current Behavior

I'm using nonceManager when instantiating my walletClient because my code can send multiple tx in parallel
I noticed that when calling walletClient.writeContract (or equivalent), if this method throws (for instance not enough gas and the tx is going to fail, hence the transaction is not triggered because estimateGas probably fails), the nonce has been incremented, and all the following transactions will just wait forever because there will be a nonce gap

Expected Behavior

If the call to writeContract or equivalent fails, the nonce should not be incremented (or be re-decremented)?

Steps To Reproduce

No response

Link to Minimal Reproducible Example

https://stackblitz.com/edit/viem-getting-started-9lqybgzb?file=index.ts

Anything else?

No response

@tmm tmm added the Good First Issue Misc: Good First Issue label Dec 18, 2024
@nmalzieu
Copy link
Author

nmalzieu commented Dec 19, 2024

I don't think the stackblitz will work actually because the account is empty and the nounce will be 0 even after the failure, but using a private key that has transactions will show the issue I have
Also I wonder if the reset method of createNonceManager should not also call nonceMap.delete(key) ? However I'm not 100% sure I understand how the nonce manager works.

0xrouss added a commit to 0xrouss/viem that referenced this issue Dec 21, 2024
@0xrouss 0xrouss linked a pull request Dec 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Misc: Good First Issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants