Repository navigation
Persist the segbuild byte counter, or a restarted node never cuts - #406
Merged
Merged
Conversation
The original design argued the counter need not be durable: it resets, the
segment in progress is cut late, and sizes are advisory anyway. That reasoning
is sound for *one* late cut and breaks at the time scale the mainnet node
actually runs at.
Measured from this node's own epoch rotations, which use the same 1,024 MB
threshold, a gigabyte of written state is 25,000 to 50,000 blocks -- nine to
eighteen days:
epoch 2 9,342,320 -> 9,367,401 25,081 blocks 8.7 days
epoch 3 9,367,401 -> 9,417,643 50,242 blocks 17.4 days
So a node restarted weekly returned to zero every time and would **never reach
the target and never cut a boundary at all**. Not "a segment cut late": no
segments, ever, with a log that looks healthy and a feature that extends
nothing. The failure is invisible, which is what makes it worth fixing rather
than documenting.
`COUNTER` is written by the poll that cuts boundaries, so the hot path is still
one relaxed atomic add -- making it durable deliberately did not move work into
the block being executed. The write is skipped when the value has not moved, so
an idle node writes nothing.
The asymmetry with the boundary log is deliberate and the module note explains
it: `COUNTER` is rewritten in place and not fsynced, while `BOUNDARIES` is
appended and fsynced. Losing the last poll's accounting to a power cut delays a
cut, which is what "advisory" genuinely covers; losing a boundary merges two
segments into one that may not fit a consumer's memory, which is the property
the sizing exists to protect. A torn or unparseable counter therefore opens as
zero rather than refusing: starting the segment over costs one late cut, and
refusing would stop the set being extended over a number that only decides
where to cut.
A cut clears the persisted value too, and only after the boundary has been
appended. Persisting the reset first would throw away a segment's worth of
accounting if the append then failed, to save nothing; leaving it means a
restart resumes the count instead.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
The design argued the segbuild byte counter need not be durable: it resets on restart, the segment in progress is cut late, and sizes are advisory anyway. That reasoning is sound for one late cut and breaks at the time scale the mainnet node actually runs at.
Measured from this node's own epoch rotations — which use the same 1,024 MB threshold, so a completed epoch's block span is a segment's:
So a node restarted weekly returned to zero every time and would never reach the target and never cut a boundary at all. Not "a segment cut late": no segments, ever, with a log that looks healthy and a feature that extends nothing. That invisibility is what makes it worth fixing rather than documenting.
What changed
COUNTERis written by the poll that cuts boundaries, so the hot path is still one relaxed atomic add — making it durable deliberately did not move work into the block being executed. The write is skipped when the value has not moved, so an idle node writes nothing.The asymmetry with the boundary log is deliberate.
COUNTERis rewritten in place and not fsynced;BOUNDARIESis appended and fsynced. Losing the last poll's accounting to a power cut delays a cut, which is what "advisory" genuinely covers. Losing a boundary merges two segments into one that may not fit a consumer's memory, which is the property the sizing exists to protect. A torn or unparseable counter therefore opens as zero rather than refusing: starting the segment over costs one late cut, and refusing would stop the set being extended over a number that only decides where to cut.A cut clears the persisted value, and only after the boundary is appended. Persisting the reset first would discard a segment's worth of accounting if the append then failed, to save nothing; leaving it means a restart resumes the count instead.
Verification
Storage 17 tests, three of them new:
COUNTERopens as zeroCLI bin 164, clippy clean.
docs/segbuild-continuous-design.md§4.1 and the §5 failure table are corrected — the old "node restarts | counter resets, so one segment is cut late. Harmless: sizes are advisory" row was the claim that turned out to be wrong.Note for deployment
The node currently running has the pre-fix binary, so its counter still resets on restart. Nothing breaks in the meantime — it cut its catch-up boundary from the executed head at startup and built
909-9420001-9429888— but the next size-driven boundary is 9–18 days out and every restart before then starts that clock over.🤖 Generated with Claude Code