Skip to content

Extend the segbuild set from a running node, by deferred re-execution - #402

Merged
SergioDemianLerner merged 2 commits into
mainfrom
segbuild/node-integration
Nov 21, 2026
Merged

SergioDemianLerner merged 2 commits into
mainfrom
segbuild/node-integration

Conversation

@SDL-A1

@SDL-A1 SDL-A1 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

The segment set covers #1..#9,420,000 and the chain keeps moving. This makes the node extend the set itself, by deciding where segments end while it syncs and re-executing each range afterwards — not by intercepting the trie store, which is what the previous attempt did and what trie-capture-design.md is the retrospective on.

Each block's written bytes go to a counter; when enough has accumulated the executed head is recorded as a boundary; once the head is --segbuild-lag blocks past it, the range is replayed out of the node's own store and sealed. Blocks are executed twice, which at the tip is about ten seconds of work per eight hours of chain.

docs/segbuild-continuous-design.md is the design in full.

Either a correct segment or no segment

A segment that under-covers its range is the worst outcome available: a missing trie node is indistinguishable at the API from a genuine absence (trie-segments-design.md §6.9d), so a consumer reads a wrong answer rather than an error.

  • Every state root is verified against its header as the range replays.
  • The segment is built under .building-A-B, which no reader parses as a segment, and renamed only after the replay reaches its end. The mismatch path, the missing-node path, a cancel and a SIGKILL all leave the same thing behind. The rename is the commit.

The collector has to be told, and a bound alone is not enough

A pending range reads historical state out of a garbage-collected store. An earlier draft of the design argued it was retained anyway, by lag < burial_depth. That argument is wrong, and it reads plausibly, so it is worth being explicit: the collection root sits at head - 4,000 while a segment is ~90,000 blocks, so the root sits inside the pending range. A node written at A+5 and dead by A+9 is reachable from no state at all; a node in the state at A-1 superseded at A+100 is not in the state at the collection root either. Both are read by the replay.

So retention is arranged, and it takes two halves that each cover what the other cannot:

keeps cannot keep
bound at A-1 what blocks at/after A wrote, including nodes created and destroyed inside the range the seed trie, written below it
pin on root(A-1) the seed trie the replay starts from the range's interior, which no state reaches

Together they are exhaustive: a node read while replaying [A..B] was written either before A — and if still needed it is in the trie at A-1 — or at/after A. One block number produces both. EpochTrieStore::collect_bounded takes the floor as min(root_block, every registered bound), the collector's own root being the bound it imposes on itself.

A held floor is an outcome, not a failure: CollectStats::held_by_bound names it, reported as heldByBound over rsk_collectTrieStatus, and the cycle returns Ok — a collection that errored once a minute would bury the failures that matter. A bound that stops advancing past --gc-max-bound-lag is overridden, loudly.

What happens when it cannot work

A range the collector has already swept beneath is written off into UNCOVERED without being attempted. The test is the store's own watermark (collected_below), not distance from the head: distance says a range lost its protection, which is not the same as having been collected — nothing is gone until a sweep reaches it, and a range that still has its nodes should still be built. Any other failure is retried twice and written off the same way. UNCOVERED is the set's list of known holes, which the offline tool fills from an archive.

Enabling it needs a current set, and the node refuses at startup otherwise — an empty set cannot be bootstrapped from here, and a gap between the set's end and the executed head cannot be built from a collected store. That is the one place segbuild may stop the node, and only before it serves anything. Nothing else in this path may be fatal: every lock in segbuild_boundaries is poison-tolerant, so a panic in a builder thread cannot panic the node's execution path on the next block.

Verified against the chain

crates/execution/tests/segment_build_from_store.rs (--ignored, needs a block store and a trie store) builds real segments from this node's own data:

running 6 tests
a_cancelled_build_leaves_no_segment_and_resumes ... ok
a_range_builds_into_a_segment_that_verifies_every_block ... ok
a_range_the_collector_swept_beneath_is_written_off_unattempted ... ok
a_watermark_below_the_range_does_not_stop_it ... ok
the_loop_cuts_a_boundary_builds_it_and_then_releases_the_floor ... ok
the_pre_unitrie_era_is_refused_rather_than_built_unverified ... ok
test result: ok. 6 passed; finished in 160.08s

The loop test is the one worth having: build_range could be entirely correct while a built range went on holding the collector's floor for ever, and nothing else would catch it.

Unit suites: storage 269, execution 1909, rpc 271, sync 670. cargo clippy --workspace --all-targets clean.

Also

segbuild_capture.rs is deleted — 471 lines of unused dual-write code implies it is the supported path. Its measurement is kept in the design document: interception cost 1.24× per-block execution after per-block batching, 7.6× without.

Still open

Whether the builder should stay idle while the node is catching up. It would free CPU for sync exactly when the node needs it, at the cost of guaranteeing the holes that the write-off rule merely records sooner — a policy decision about a production node rather than a code question. §7.3 has the arithmetic.

🤖 Generated with Claude Code

SergioDemianLerner and others added 2 commits November 21, 2026 10:02
The segment set covers #1..#9,420,000 and the chain keeps moving. Rebuilding it
from a 131 GB archive every time does not scale, so the node extends it itself.
Not by intercepting the trie store, which is what the previous attempt did and
what docs/trie-capture-design.md is the retrospective on: interception made a
segment a side effect of whatever the node happened to execute, uncles included,
so it stopped being the read set of its range -- the only property that makes a
segment verifiable.

Instead the node counts and decides, and a background task re-executes. Each
block's written bytes go to a counter; when enough has accumulated the executed
head is recorded as a segment boundary; once the head is --segbuild-lag blocks
past that boundary, the range is replayed out of the node's own store and sealed.
Blocks are executed twice, which at the tip is about ten seconds of work per
eight hours of chain.

Either a correct segment or no segment
--------------------------------------

A segment that under-covers its range is the worst outcome available, because a
missing trie node is indistinguishable at the API from a genuine absence
(trie-segments-design.md 6.9d): a consumer reads a wrong answer rather than an
error. Two things make that unreachable rather than unlikely. Every state root
is verified against its header as the range replays. And the segment is built
under `.building-A-B`, which no reader parses as a segment, and renamed only
after the replay reaches its end -- so the mismatch path, the missing-node path,
a cancel and a SIGKILL all leave the same thing behind. The rename is the commit.

The collector has to be told, and a bound alone is not enough
------------------------------------------------------------

A pending range reads historical state out of a garbage-collected store, so
something has to keep it. An earlier draft of the design argued it was kept
anyway, by lag < burial_depth. That argument is wrong, and this is worth being
explicit about because it reads plausibly: the collection root sits at
head - 4,000 while a segment is ~90,000 blocks, so the root sits *inside* the
pending range, not below it. A node written at A+5 and dead by A+9 is reachable
from no state at all, and a node in the state at A-1 that is superseded at A+100
is not in the state at the collection root either. Both are read by the replay.

So retention is arranged, and it takes two halves that each cover what the other
cannot:

  - a *bound* at A-1 keeps what blocks at or after A wrote, including nodes
    created and destroyed inside the range, which no state at either end
    reaches; a pin cannot express that, because it keeps reachability;
  - a *pin* on the state root at A-1 keeps the seed trie, which the bound cannot
    keep, because those nodes were written below it.

Together they are exhaustive: a node read while replaying [A..B] was written
either before A -- and if it is still needed it is in the trie at A-1 -- or at
or after A. One block number produces both, and EpochTrieStore::collect_bounded
takes the floor as min(root_block, every registered bound), the collector's own
root being simply the bound it imposes on itself.

A held floor is an outcome, not a failure. CollectStats::held_by_bound names it
and the cycle returns Ok, because a collection that errored once a minute would
bury the failures that matter. A bound that stops advancing past
--gc-max-bound-lag is overridden, loudly: an incomplete segment set is a thing
to repair later, a node out of disk is not.

What happens when it cannot work
--------------------------------

A range the collector has already swept beneath is written off into UNCOVERED
without being attempted. The test is the store's own watermark
(collected_below), not the builder's distance from the head, and the distinction
matters: distance says a range lost its protection, which is not the same as
having been collected -- nothing is gone until a sweep reaches it, and a range
that still has its nodes should still be built. A build that fails for any other
reason is retried twice and then written off the same way. UNCOVERED is the set's
list of known holes, which the offline tool can fill from an archive; the
alternative is a builder that loops on the one range it cannot do while every
later range starves.

Enabling it needs a current set, and the node refuses at startup otherwise: a
directory with no NNN-start-end segment cannot be bootstrapped from here (the
pre-fork era needs a baseline), and a gap between the set's end and the executed
head cannot be built from a collected store. That is the one place segbuild may
stop the node, and only before it serves anything.

Nothing else in this path may be fatal. Every lock in segbuild_boundaries is
taken poison-tolerantly, so a panic in a builder thread cannot poison a lock and
then panic the node's execution path on the next block; the builder's outcomes
are an enum the caller logs. Extending the set is a by-product of syncing, and
failing to extend it is not a reason to stop following the chain.

Verified against the chain, not argued
--------------------------------------

crates/execution/tests/segment_build_from_store.rs builds real segments from
this node's block store and the archive trie: a range at #9,000,000 verifies
every state root and contains the seed node for its own first block, a killed
build resumes to the identical segment, the pre-fork era is refused rather than
built unverified, and the whole loop -- boundary cut at the executed head,
refused inside the lag, built once settled, recorded against the chain's hash,
floor released -- runs end to end. That last assertion is the one worth having:
build_range could be entirely correct while a built range went on holding the
collector's floor for ever, and nothing else would catch it.

segbuild_capture.rs is deleted. 471 lines of unused dual-write code implies it
is the supported path. Its measurement is kept in the design document:
interception cost 1.24x per-block execution after per-block batching, 7.6x
without.

docs/segbuild-continuous-design.md is the design, including what is still open:
whether the builder should stay idle while the node is catching up, which trades
segment coverage for sync speed and is a policy decision about a production node
rather than a code question.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CI caught five flags in neither ONE_SHOT nor CONFIGURABLE, which is the drift
guard in config_file doing its job: --gc-max-bound-lag and the four --segbuild-*
flags were command-line only, so a node started from node.toml could not turn
segbuild on at all. The list entry is the smallest part of the fix.

[gc] gains max_bound_lag, and a new [segbuild] section carries out, target_mb,
lag and seal_mb, each wired through apply_file_config. Listing a flag without
that wiring does not pass: `# default: unset` is checked by applying the value
shown and finding which Args field moved, so a key that drives nothing is
reported as either unwired or wrongly marked.

Both example files document all five with their defaults, because one test
requires the example to name every option by reflection -- a new Option is a new
null until it is documented -- and another requires the reference and light
examples to cover the same keys.

`out` is the one marked `# default: unset`: unset is how the feature stays off,
and the node refuses to start if the directory it names is not a current
segment set.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@SergioDemianLerner
SergioDemianLerner merged commit be5d08e into main Nov 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants