-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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: running script with --broadcast
for a transaction sequence can error out due to nonce desync from rpc latency
#9096
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provider reporting nonce which is behind might mean several things — there might've been a reorg or node might just still be updating state even though block with previous nonce was already included but latest
state is not yet updated
in both cases we'd want to wait until we are sure that previous transaction is available in state because otherwise estimate_gas below might fail
let's add a loop here which would do several attempts at fetching and comparing nonce with some delay, and if after eg 5 iterations we still have a mismatch we'd always fail
implemented a loop, seems to do the job, as my test broadcasts all work well should I change implementation in any way? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, a couple nits
--broadcast
for a transaction sequence can error out due to nonce desync from rpc latency
… error out due to nonce desync from rpc latency (foundry-rs#9096) * fix for issue foundry-rs#9095 * changed 'if' statement into 'match' * fmt fix * repeat ask for provider nonce on desync * loop break and tokio::time use instead of std::thread
Motivation
On some chains with fast block times and/or relatively high latency providers, running a deployment script with
--broadcast
that sends a sequence of transactions can lead to the script failing, as the RPC will report an older nonce for the EOA.Solution
If the RPC is out of sync with the current nonce, there's two options:
If it returns a nonce that is ahead, it likely means that the EOA executed some other transaction meanwhile, so the script should stop.
However, if the nonce is ahead, the culprit is likely a slow RPC. In that case, it makes sense to continue to proceed with the transaction sequence.
Treating these two cases separately means the sequence of transactions won't get stopped out.