Skip to content

fix(anvil): fix latest read isolation - #16368

Open
cruzdanilo wants to merge 1 commit into
foundry-rs:masterfrom
cruzdanilo:sync
Open

fix(anvil): fix latest read isolation#16368
cruzdanilo wants to merge 1 commit into
foundry-rs:masterfrom
cruzdanilo:sync

Conversation

@cruzdanilo

@cruzdanilo cruzdanilo commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

motivation

during successful mining, anvil could publish the new database state before the corresponding evm_env. an overlapping eth_call at latest could therefore execute against state from n+1 with the block environment from n.

this follows #10709, which fixed an earlier race while resolving latest, and #12417, which fixed another case where the rpc head and the number opcode disagreed. this change addresses the remaining publication race after latest has already been resolved.

solution

publish the updated execution environment while holding the existing database write lock after a successful state commit. live calls acquire the database read lock before cloning the environment, so they now observe either the old or new snapshot coherently while retaining concurrent call execution. the consistent db then evm_env lock order has no reverse acquisition path and therefore introduces no deadlock cycle.

a deterministic regression test fixes the mining and call ordering and verifies that state and block number come from the same snapshot.

codex assisted with codebase analysis, test generation, implementation, and drafting this pull request description.

pr checklist

  • added tests
  • added documentation
  • breaking changes

@github-actions

Copy link
Copy Markdown
Contributor

✅ Changelog found

The deterministic check will validate the changed entry.

Comment thread crates/anvil/src/eth/backend/mem/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants