-
Notifications
You must be signed in to change notification settings - Fork 224
InvalidNonce error when interacting with the chain via scripts #2036
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
Comments
Hi @milancermak , thanks for opening an issue. Some rpc nodes are configured with higher poll intervals, which means they may return "older" nonces in pending blocks, or even not be able to obtain pending blocks at all. It seems yours may be this case. Have you tried to set the nonce manually for all the transactions you try to do? You could try to get_nonce once at the beggining of your script, and then increment it and use for transactions, something like:
Of course you might need to be careful with this as well, since it still may happen wrong nonce is used for some transactions (eg some transactions are skipped after get_nonce, and the nonce is incremented manually - next tx will then have a wrong nonce). Please let me know if this mitigates your problem. As a side note, we plan to migrate script execution to multicalls to prevent these issues in the future #823 |
Ok, I see what you're saying. I won't change it in my script now because 1) it's already deployed and 2) it would be require some refactoring, passing the nonce into subfunctions manually etc. I'll keep it in mind for the future though, will write my scripts with manual nonce handling. Still, it would be great if you could find some way around the issue. From my perspective, I would rather have the script take longer, but be guaranteed to finish than to babysit it and rerun it again and again. Also, thank you for the idempotency feature ❤️ Re: multicalls - I'm not sure that would help in my particular case. AFAIK, in a multicall context, we can't use the output of call 1 in call 2, which is crucial if the multicall would be a declare + deploy + invoke. |
If you are using a recent sncast version, you should be using state files, which means all the transactions that succeeded and are present in the state file won't be repeated 👍 But I see your point.
Sure, thanks fot the suggestion! Actually, we plan to add new functions to script (to get tx receipt, its status and its hash) and the plan is they could be used to achieve exactly what you say! I will also try to find other, less-bruteforcy ways to achieve that to give users more options. If there is something more I can help you with, please let me know. Otherwise I will proceed with closing this issue shortly. thanks! |
Which component is your bug related to?
sncast
Foundry Version
0.21.0
What operating system are you using?
MacOS
What system architecture are you using?
arm
What happened
I'm using a script to deploy a protocol. It consists of ~20 contracts, each needing a declare + deploy, plus some additional transactions to set up roles and whatnot. In total the deploy script might do about 50+ operations.
I have to run the script multiple times because it often fails. It seems it's because of a wrong nonce value, because this is an error that I have in the state json file:
When the fail happens, it's always the same error - account nonce is 1 greater than incoming tx nonce.
Sometimes the script makes only 1 TX and fails immediately, sometimes multiple TXs go through (the best I got was 15, but usually it fails after 2 or 3).
This is an example output of the script:
And on the subsequent run:
I guess the issue is somewhat similar to #1336 I reported some time ago, but that one was fixed.
Trace
No response
Is there an existing issue for this?
The text was updated successfully, but these errors were encountered: