This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
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
gets rid of a flaky test as seen here https://github.com/gakonst/ethers-rs/runs/6740032643?check_suite_focus=true
by explicitly setting the nonce
there's a possible race condition rn on anvil if multiple tx without nonce are sent via
eth_sendTransaction
because the next nonce is determined byonchain +num(pool)
however if multiple tx are sent at the same time they might get the same nonce if the
nextNonce
for an additional tx is determined before the previous was added to the pool.https://github.com/foundry-rs/foundry/blob/25241a63db896c88b1717c5522ac284724003eb8/anvil/src/eth/api.rs#L547
https://github.com/foundry-rs/foundry/blob/25241a63db896c88b1717c5522ac284724003eb8/anvil/src/eth/api.rs#L569
this could be prevented via an import lock or some additional check against the
Already Imported
error but not sure if that's worth it @gakonst ?the former would have some performance impact because we need to lock for the entire
sendTransaction
function, for the latter we can try to implement an additional attempt: iftx.nonce
wasNone
and we received anAlready Imported error
try again with new nonce until notAlready Imported error
.Solution
failing
watch_events
test fixed in anvil: foundry-rs/foundry#1861PR Checklist