Repository navigation
cl/phase1/forkchoice/fork_graph: skip re-dumping an already dumped head state - #25539
Merged
Merged
Conversation
…ady dumped root On Gloas the ForkChoice stage runs again for the same head root when the head's payload status changes from EMPTY to FULL, and about once per second while the forkchoice update returns busy. Each run dumped the same unchanged head state again: a full SSZ encode and file rewrite under stateDumpLock, which disk state reads also need. DumpBeaconStateOnDisk now remembers the block root and slot of its last successful dump and returns early when both match. The slot is part of the key because a state advanced through empty slots keeps its block root. The marker is cleared before each write and set only after a successful close, so a failed write is retried and never leaves a truncated file behind a skip.
… done DumpBeaconStateOnDisk recorded the last dumped root and slot in a defer that only checked err == nil. A panic during encode, open, write or header lookup leaves err nil, so the marker was set although the file was truncated or only partly written. The stage runner recovers panics, so the next dump of the same root and slot was skipped and the broken file stayed on disk. Record the marker in the close defer, only after the function reached its normal return and Close succeeded. Also simplify the dump tests: count writes with the existing envelopeWriteFailureFs close counter, use forced dumps and SetSlot instead of processing slots, and merge the close-error retry test into TestDumpBeaconStateReturnsCloseError.
yperbasis
approved these changes
Oct 30, 2026
yperbasis
left a comment
Member
There was a problem hiding this comment.
Approving at 6b00deb.
Two optional nits:
- The struct comment "reusable disk I/O buffers, each guarded by the mutex above it" now also heads
lastDumpedRootandlastDumpedSlot, which are not buffers. - Clearing only
lastDumpedRootbefore a write leaves a stalelastDumpedSlot. A zero block root cannot occur, so this is harmless, but clearing both fields would make the "nothing dumped" state explicit.
Both commits cherry-pick cleanly onto release/3.8 and the new tests pass there. The related performance fixes were all backported, so this one probably should be too.
Member
Author
|
@yperbasis thanks, both nits are addressed:
Backport: agreed, I will open a backport PR to release/3.8 after this one merges. With the new commits, all five commits still cherry-pick cleanly onto release/3.8, and the fork_graph tests pass there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Gloas the ForkChoice stage runs again for the same head root when the head's payload status changes from EMPTY to FULL (
GetExecutionHeadchanges andsleep_for_slot.gowakes the stage), and again about once per second while the forkchoice update returns busy. Each run callspostForkchoiceOperations, which dumps the head state withDumpBeaconStateOnDisk. The envelope does not change the beacon state, so every extra run encodes and rewrites the same state for the same root.A head-state dump takes about 405 ms p50 on a mainnet node with the current dump code (no fsync since #25251), and it holds
stateDumpLock, which disk state reads (replays) also need. By code reasoning this can add up to 8 redundant dumps per epoch on Gloas (one per dump slot, more while the forkchoice update is busy). There is no Gloas mainnet data for this yet.Fix
forkGraphDiskremembers the block root and slot of its last successful state dump, guarded bystateDumpLock.DumpBeaconStateOnDiskreturns early when both match. The slot is part of the key because a state advanced through empty slots keeps its block root but has different content. The marker is cleared before each write and set only after the write finished and the file closed without error, so a failed or panicked write is retried (stage panics are recovered, so the next run would otherwise skip a truncated file).Tests
New tests in
fork_graph_test.gocount state-file writes through the existing failing-fs wrapper:TestDumpBeaconStateReturnsCloseError);TestDumpBeaconStateRetriesAfterPanic);Each test fails when the production branch it targets is removed.
Out of scope
stateDumpLockcontention between state dumps and replays in general, and making the state dump atomic (temp file + rename).Related to #25120 and #25136.