Skip to content

feat(l1): EIP-8189 snap/2 (BAL-based state healing)#6544

Draft
edg-l wants to merge 3 commits intomainfrom
snap-v2
Draft

feat(l1): EIP-8189 snap/2 (BAL-based state healing)#6544
edg-l wants to merge 3 commits intomainfrom
snap-v2

Conversation

@edg-l
Copy link
Copy Markdown
Contributor

@edg-l edg-l commented Apr 28, 2026

Motivation

Implements EIP-8189: snap/2, which replaces iterative trie-node fetching during state healing with Block Access List (EIP-7928) replay. This is cleaner, avoids the need for partial-trie reconstruction, and lets the local node serve the same BALs to peers over snap/2 once sync is complete.

Depends on EIP-7928 (BAL header commitment) already present in this repo.

Description

Wire protocol

  • Advertises snap(2) alongside snap(1); per-connection negotiation picks the highest common version.
  • New messages: GetBlockAccessLists (0x08) and BlockAccessLists (0x09).
  • snap/2 connections reject GetTrieNodes/TrieNodes; snap/1 connections serve them unchanged.
  • BlockAccessLists response: Vec<Option<BlockAccessList>> with 0x80 RLP sentinel for absent entries, preserving position correspondence with the request.
  • Compile-time assertions in rlpx/message.rs guard the new message range against BASED_CAPABILITY_OFFSET.

BAL persistence

  • New storage table BLOCK_ACCESS_LISTS with store_block_access_list, get_block_access_list, iter_block_access_lists_by_hashes.
  • execute_block returns Option<BlockAccessList>; store_block takes Option<&BlockAccessList>. Pre-Amsterdam blocks pass None.
  • All block-import paths thread the BAL: add_block, add_block_pipeline_inner, add_blocks_in_batch.
  • BAL hash validated once per block in execute_block / execute_block_from_state.

Server / client / replay engine

  • Server process_block_access_lists_request respects a 2 MiB soft cap (BAL_RESPONSE_SOFT_CAP_BYTES); first slot always included; remaining over-cap slots filled with None.
  • Client request_block_access_lists returns (Vec<Option<BlockAccessList>>, peer_id) to keep failure attribution coherent.
  • apply_bal (sync/bal_healing/apply.rs) applies BAL as state diffs: balance/nonce/code/storage post-values; implicit-empty entry triggers account deletion; missing local slots treated as zero pre-value; storage writes go directly to backend.
  • advance_state_via_bals fetches in batches, validates ordering/hash before each apply, applies in strict block order using locally-tracked current_root, persists each BAL. On peer exhaustion falls back to snap/1 heal_state_trie_wrap.

Sync state machine

Staleness loop in snap_sync.rs branches on snap/2 peer reachability: V2 path runs advance_state_via_bals then validates final state_root; V1 path is unchanged.

Tests

  • 6 codec round-trip tests for new wire types.
  • 5 server tests for process_block_access_lists_request (empty, all-known, mixed, 2 MiB cap, snap/1 rejection).
  • 7 apply_bal unit tests: account creation/destruction, storage deletion, code deployment, EIP-7702 delegation clear, fresh storage slot, bad-state-root detection.
  • 1 batch-import BAL persistence regression test in test/tests/blockchain/batch_tests.rs.
  • 3 storage tests for the new BAL API.
  • cargo test -p ethrex-p2p: 37 passing (was 27). cargo test -p ethrex-test: 421 passing (was 416).

Notes

  • End-to-end multi-node snap/2 integration tests (8.5/8.6 from the EIP) are deferred. test/tests/p2p/ has no multi-node RLPx harness, and the existing hive devp2p snap simulator calls the external Go devp2p CLI. A dedicated hive snap/2 simulator is needed.
  • Updated STORE_SCHEMA_VERSION in crates/storage/lib.rs for the new BLOCK_ACCESS_LISTS table.

Checklist

  • Updated STORE_SCHEMA_VERSION (crates/storage/lib.rs) if the PR includes breaking changes to the Store requiring a re-sync.

edg-l added 3 commits April 28, 2026 13:24
Adds snap/2 capability advertisement, GetBlockAccessLists (0x08) /
BlockAccessLists (0x09) message types with version-aware Message
dispatch, BAL storage API, and BAL persistence in all block-import
paths. snap/1 remains supported. No server/client/healing logic yet;
those land in the next run.
Adds the GetBlockAccessLists server responder with a 2 MiB cumulative
soft cap, the client request method that returns the serving peer id
for accurate failure attribution, the apply_bal / advance_state_via_bals
replay engine with strict in-order application and per-block hash
verification, and the snap_sync state machine branch that uses BAL
replay under snap/2 with a final state-root check, falling back to
snap/1 trie healing otherwise.
Adds server-side unit tests for process_block_access_lists_request
(empty / known / mixed / size-cap / snap/1 dispatch rejection),
two more apply_bal cases (pre-state-gap fresh storage slot creation
and bad-state-root detection), and updates the public and internal
snap_sync docs plus the sync_modes doc with the snap/2 wire protocol
and BAL replay flow. End-to-end multi-node integration tests are
deferred to a future external hive snap/2 simulator.
@github-actions github-actions Bot added the L1 Ethereum client label Apr 28, 2026
@github-actions
Copy link
Copy Markdown

Lines of code report

Total lines added: 1232
Total lines removed: 0
Total lines changed: 1232

Detailed view
+-----------------------------------------------------------+-------+------+
| File                                                      | Lines | Diff |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs                    | 2509  | +22  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/error.rs                         | 150   | +3   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_committer.rs                | 1371  | +1   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection/codec.rs     | 251   | +9   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection/handshake.rs | 508   | +13  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection/server.rs    | 1397  | +33  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/message.rs              | 497   | +79  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/snap/codec.rs           | 465   | +181 |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/snap/messages.rs        | 78    | +14  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/snap/mod.rs             | 9     | +2   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/snap/client.rs               | 1280  | +99  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/snap/constants.rs            | 26    | +3   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/snap/mod.rs                  | 23    | +1   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/snap/server.rs               | 194   | +44  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/sync.rs                      | 319   | +7   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/sync/bal_healing/apply.rs    | 393   | +393 |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/sync/bal_healing/mod.rs      | 212   | +212 |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/sync/snap_sync.rs            | 1177  | +28  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/storage/api/tables.rs                       | 24    | +1   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs                            | 2713  | +87  |
+-----------------------------------------------------------+-------+------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant