Multichain Scripts: Deploy each sequence of transactions sequentially instead of in parallel. #6271
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
As explained here foundry first runs a simulation, collects all the transactions then batch runs all the transactions. This causes issues in scenarios where the script has a flow like this:
In this case, steps 1 and 3 will generate two sequences of transactions both pertaining to Chain A. From the simulation that was previously run, the nonce of the first transaction in Sequence 3 will be one more than the nonce of the last transaction in Sequence 1. However, since foundry attempts to run both Sequences 1 & 3 in parallel, the nonce returned from the RPC will mismatch the first transaction in Sequence 3, and it'll result in the following error:
I can see that multiple users have also run into this issue: #4701 #6184
Solution
We can still run the transactions in each DeploySequence in parallel and enjoy the performances of batch transactions! However, in between sequence changes we have to wait until the last sequence's transactions are all submitted.
Potential Optimization
We could chunk the neighbouring sequences and execute those in parallel. Consider Chains A, B, C and a deploy script that results in these sequences:
A, B, A, B, B, C, A, B, B, A, A, C, C, C
We could chunk the neighbouring sequences like so:
A, B, A, (B, B), C, A, (B, B), (A, A), (C, C, C)
Although this may already be the case, I'm not sure how these sequences get generated.