Skip to content

fix(anvil): make fork resets atomic - #15919

Draft
mablr wants to merge 15 commits into
masterfrom
mablr/fix-anvil-reset-atomicity
Draft

fix(anvil): make fork resets atomic#15919
mablr wants to merge 15 commits into
masterfrom
mablr/fix-anvil-reset-atomicity

Conversation

@mablr

@mablr mablr commented Jul 27, 2026

Copy link
Copy Markdown
Member

Anvil currently mutates live fork metadata and fee state while anvil_reset is still performing asynchronous, fallible setup. A failed reset can therefore expose partially updated node state, and reset can race active mining.

This prepares the candidate configuration, database, EVM environment, genesis allocation, and fee state independently, then publishes them only after setup succeeds. It also preserves chain-ID override and database RPC provenance, keeps local signers aligned with the active chain after a reset, delays instance-ID changes until the backend commits successfully, and snapshots active blob parameters for each fee-history entry.

This includes #15908, which adds target-fork hardfork and fee inference on top of the atomic reset path. It is stacked on #15931, which isolates persisted fork caches by endpoint so publishing a replacement cannot later be contaminated by the retired database's final cache flush.

This PR was written with Amp, which assisted with code generation, tests, and review. PR responses may also be generated with Amp.

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

✅ Changelog found

The deterministic check will validate the changed entry.

@mablr
mablr marked this pull request as ready for review July 27, 2026 21:16

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One fork cache isolation regression.

Comment thread crates/anvil/src/eth/backend/mem/mod.rs Outdated
Comment thread crates/anvil/src/eth/backend/mem/mod.rs Outdated
Prevent retired fork backends from overwriting replacement state by assigning each RPC endpoint its own persisted cache file. Keep cache reporting compatible with legacy and endpoint-specific files.

Amp-Thread-ID: https://ampcode.com/threads/T-019fa7db-8788-7159-b3d6-5dcdeb97c522
Co-authored-by: Amp <amp@ampcode.com>
mattsse
mattsse previously approved these changes Jul 28, 2026

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

mablr and others added 3 commits July 28, 2026 11:39
Prepare fork configuration, database, EVM environment, and fee state without mutating the live backend. Publish the candidate only after setup succeeds so failed resets preserve the active node state.
FeeManager is constructed before a historical fork's hardfork is detected, which leaves its fee calculations on the default spec. Share the active spec across clones and update it during fork setup so pre-London simulations cannot derive EIP-1559 base fees.

Replace the ineffective empty-block check with a local historical fork regression that carries a nonzero base fee override into the following simulated block.
Preserve fork database RPC provenance across mutable configuration updates. Snapshot the active shared blob parameters for each fee-history entry so hardfork-changing resets use the target fork's schedule.

Amp-Thread-ID: https://ampcode.com/threads/T-019fa7db-8788-7159-b3d6-5dcdeb97c522
Co-authored-by: Amp <amp@ampcode.com>
@mablr
mablr force-pushed the mablr/fix-anvil-reset-atomicity branch from 87e6077 to fe27231 Compare July 28, 2026 09:42
@mablr
mablr changed the base branch from master to mablr/isolate-anvil-fork-cache July 28, 2026 09:42
@mablr
mablr marked this pull request as draft July 28, 2026 09:46
Base automatically changed from mablr/isolate-anvil-fork-cache to master July 28, 2026 10:18
mablr added 7 commits July 28, 2026 12:38
Keep network-family provenance and EIP-1559 parameters synchronized across fork resets. Reject unsupported inferred network-family changes before publishing candidate state.
# Conflicts:
#	crates/anvil/src/config.rs
#	crates/anvil/src/eth/api.rs
#	crates/anvil/src/eth/backend/fork.rs
#	crates/anvil/src/eth/backend/mem/mod.rs
#	crates/anvil/src/eth/miner.rs
#	crates/anvil/src/lib.rs
#	crates/anvil/tests/it/eip4844.rs
#	crates/anvil/tests/it/optimism.rs
#	crates/anvil/tests/it/simulate.rs
mablr added 4 commits August 11, 2026 17:09
# Conflicts:
#	crates/anvil/src/config.rs
#	crates/anvil/src/eth/api.rs
#	crates/anvil/src/eth/backend/fork.rs
#	crates/anvil/src/eth/backend/mem/mod.rs
#	crates/anvil/src/eth/fees.rs
#	crates/anvil/src/eth/miner.rs
#	crates/anvil/src/service.rs
#	crates/anvil/tests/it/simulate.rs
Amp-Thread-ID: https://ampcode.com/threads/T-019ff4ec-c3e3-773f-8805-247b7dbe62d9
Co-authored-by: Amp <amp@ampcode.com>

# Conflicts:
#	crates/anvil/src/config.rs
#	crates/anvil/src/eth/api.rs
#	crates/anvil/src/eth/backend/fork.rs
#	crates/anvil/src/eth/backend/genesis.rs
#	crates/anvil/src/eth/backend/mem/mod.rs
#	crates/anvil/src/eth/fees.rs
#	crates/anvil/src/eth/sign.rs
#	crates/anvil/src/lib.rs
#	crates/anvil/tests/it/gas.rs
mablr added a commit that referenced this pull request Aug 12, 2026
Drop the missing-hash reset regression that belongs to the broader atomic reset work in #15919. The exact-fork ancestry fix continues to validate the resolved hash inside the existing staged reset path.
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.

3 participants