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: running script with --broadcast for a transaction sequence can error out due to nonce desync from rpc latency #9096

Merged
merged 11 commits into from
Oct 14, 2024

Conversation

pogobounce
Copy link
Contributor

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.

Copy link
Member

@klkvr klkvr left a 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

@pogobounce
Copy link
Contributor Author

@klkvr

implemented a loop, seems to do the job, as my test broadcasts all work well

should I change implementation in any way?

@pogobounce pogobounce requested a review from klkvr October 13, 2024 13:23
Copy link
Member

@klkvr klkvr left a 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

crates/script/src/broadcast.rs Outdated Show resolved Hide resolved
crates/script/src/broadcast.rs Show resolved Hide resolved
@pogobounce pogobounce requested a review from klkvr October 14, 2024 07:35
@zerosnacks zerosnacks changed the title fix for issue #9095 fix: running script with --broadcast for a transaction sequence can error out due to nonce desync from rpc latency Oct 14, 2024
@klkvr klkvr enabled auto-merge (squash) October 14, 2024 12:26
@klkvr klkvr merged commit 6f7c1f7 into foundry-rs:master Oct 14, 2024
22 checks passed
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
… 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
@grandizzy grandizzy added T-bug Type: bug C-forge Command: forge labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-bug Type: bug
Projects
Archived in project
3 participants