Skip to content

fix(anvil): respect configured genesis number when restoring genesis_hash#14488

Open
AissataF wants to merge 2 commits intofoundry-rs:masterfrom
AissataF:fix-load-blocks-block
Open

fix(anvil): respect configured genesis number when restoring genesis_hash#14488
AissataF wants to merge 2 commits intofoundry-rs:masterfrom
AissataF:fix-load-blocks-block

Conversation

@AissataF
Copy link
Copy Markdown

BlockchainStorage::load_blocks was hardcoding block_number == 0 to detect the genesis block during state-snapshot restore. With --block-number 73 --load-state ..., no loaded block matched, so genesis_hash kept pointing at the dummy block from BlockchainStorage::new() and Earliest / Safe / Finalized tag lookups returned the wrong hash.

Stored genesis_number on BlockchainStorage and compare against it in load_blocks instead. All existing constructors (new, forked, empty) wire the new field through.

the meaningful diff in load_blocks is one line — block_number == 0 becomes block_number == self.genesis_number. The follow-up commit adds a regression test that sets genesis_number = 73, loads a serialized block at 73, and asserts genesis_hash is rewritten to the loaded hash. There is also a sanity case proving that with genesis_number = 0 and no block 0 in the snapshot, the dummy genesis_hash is preserved

— i.e. the new test would have failed under the old hardcoded == 0 logic

…_hash`

`BlockchainStorage::load_blocks` was hardcoding `block_number == 0` to detect the genesis block during state-snapshot restore, so a non-zero genesis (e.g. `--block-number 73 --load-state ...`) left `genesis_hash` pointing at the dummy block created in `new()`. Store `genesis_number` on `BlockchainStorage` and compare against it, so `Earliest`/`Safe`/`Finalized` tag lookups return the actual restored hash. Extends the partial fix from foundry-rs#12645.
Regression test for the fix in 3a7634f: when `BlockchainStorage` is
configured with a non-zero `genesis_number` (e.g. `--block-number 73
--load-state ...`), `load_blocks` must rewrite `genesis_hash` to the
loaded block matching `genesis_number` instead of the hardcoded block 0.
@AissataF AissataF force-pushed the fix-load-blocks-block branch from 62c78b2 to 52e84b6 Compare April 28, 2026 15:24
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.

1 participant