Skip to content

core, eth/protocols/snap, eth/downloader: snap/2 sync logic#34626

Draft
jrhea wants to merge 18 commits intoethereum:masterfrom
jrhea:snap2-protocol-bal-req
Draft

core, eth/protocols/snap, eth/downloader: snap/2 sync logic#34626
jrhea wants to merge 18 commits intoethereum:masterfrom
jrhea:snap2-protocol-bal-req

Conversation

@jrhea
Copy link
Copy Markdown
Contributor

@jrhea jrhea commented Mar 31, 2026

Summary

Replace the snap/1 sync logic with snap/2's.

What changed

  • Healing removed. The syncer no longer requests trie nodes from peers. Snap/1 serving is unchanged.

  • Sync loop restructured. Sync() runs a download -> catch-up -> trie rebuild loop.

    • Download. Still fetches account ranges, storage slots, and bytecodes from peers, writing flat state to disk. When the downloader restarts the syncer with a new pivot root, the syncer detects the change and runs BAL catch-up before resuming download.

    • BAL catch-up. When the pivot moves, catchUp() fetches BALs from peers, verifies them against block headers, and applies the state diffs.

    • Trie rebuild. After download completes, triedb.GenerateTrie() rebuilds all tries from the flat state.

  • Deep reorg detection. The downloader checks if the old pivot was reorged before restarting the syncer. If so, sync progress is wiped and the syncer starts fresh.

  • Skip snapshot generation. The downloaded flat state is the snapshot. SnapSyncComplete calls RebuildFromSyncedState() instead of Rebuild().

Notes

  • Storage roots left stale during sync. When BALs are applied during catch-up, account storageRoot fields become inconsistent. Rather than recomputing storage tries on every pivot move, they are left stale and all storage tries are rebuilt at the end from flat state.

  • On deep reorg we restart from scratch. A reorg > 64 blocks is catastrophic and rare enough that we wipe sync progress and start over. Causes include:

    • finality reversion case (33%+ validators slashed)
    • long period without finality
  • Current pivot is HEAD-64. Shorter slot times or faster finality could impact this.

Follow-up PRs

  • Metrics and progress logging. Add counters and timers for access list fetch/apply, trie rebuild, and pivot movements.

  • BALs are currently stored in the KV store. Long-term, they probably need to move to the freezer for cheaper retention over the weak subjectivity period.

@jrhea jrhea changed the title Snap2 protocol bal req eth/protocols/snap, eth/downloader: BAL request Mar 31, 2026
@jrhea jrhea added the snap/2 label Mar 31, 2026
@jrhea jrhea force-pushed the snap2-protocol-bal-req branch 4 times, most recently from 053a490 to d6bcd47 Compare March 31, 2026 16:34
@jrhea jrhea changed the title eth/protocols/snap, eth/downloader: BAL request eth/protocols/snap, eth/downloader: BAL request + sync Apr 1, 2026
@jrhea jrhea force-pushed the snap2-protocol-bal-req branch 7 times, most recently from d08322a to 0fb927f Compare April 3, 2026 19:36
@jrhea jrhea force-pushed the snap2-protocol-bal-req branch from 0286103 to 72c04c3 Compare April 7, 2026 14:22
@jrhea jrhea force-pushed the snap2-protocol-bal-req branch from 72c04c3 to d111e9f Compare April 7, 2026 14:28
@jrhea jrhea changed the title eth/protocols/snap, eth/downloader: BAL request + sync core, eth/protocols/snap, eth/downloader: BAL request + sync Apr 7, 2026
@jrhea jrhea changed the title core, eth/protocols/snap, eth/downloader: BAL request + sync core, eth/protocols/snap, eth/downloader: snap/2 sync logic Apr 7, 2026
@jrhea jrhea marked this pull request as ready for review April 7, 2026 17:37
@jrhea jrhea requested a review from rjl493456442 as a code owner April 7, 2026 17:37
@jrhea jrhea marked this pull request as draft April 7, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant