Repository navigation
Description
segbuild stops at block 9,230,008. The node is at 9,422,658, so 192,650 blocks have no segment. Extending it needs a tool, and the question raised was whether there is a deadline before the node prunes away the state required.
The measurement, which looks alarming
The node's epoch trie records its sweep floor:
/var/lib/rustock/trie-epochs-flat/collected-below -> 9342320
So state below #9,342,320 is gone from the node, against a segbuild frontier of #9,230,008. The 112,311 blocks between them already have no state in the node's own trie. Retention is head - collected_below ≈ 80,000 blocks, consistent with --gc-epochs 4 --gc-rotate-mb 1024 (~1 GB per epoch at ~40 KB of trie per block ≈ 26k blocks each). At RSK's block rate that window is on the order of weeks, not months.
But the state is not actually lost, and this is the important part
Extending segbuild does not need the node's trie. build_segments seeds from a parent state root and goes forward, writing segments as a by-product. Segment 096-9229944-9230008 holds the state at #9,230,008 — so a worker can seed there and replay forward to the head, regenerating exactly the state the node has swept.
What forward replay needs is blocks, not trie. At the 187 blocks/s the full re-execution sustained, 192,650 blocks is about 17 minutes of execution (slower in practice, since build_segments also writes trie rather than discarding it).
So the dependency to protect is block availability, not trie retention. That reorders the risk: #271 (prune headers and uncles) and #272 (streaming client, never write blocks) are what would actually make segbuild unextendable, and neither has landed.
One open question I have not yet answered: whether the archival trie at /mnt/import/rustock-trie (131 GB) covers the 9.23M–9.42M range. It verified at seven heights from #1,591,001 to #9,133,347. If it reaches the head it is a second, cheaper source than forward replay; if it stops near 9.13M it is not. Worth measuring before building anything.
What to build
- An extend mode for the segment builder: seed from the highest existing segment's end state, replay forward to a target height, seal new segments on the same
NNN-start-endconvention. No archival snapshot required. - An alarm on the right invariant. Not "the trie is about to prune" — that is already true and survivable — but "the blocks segbuild would need are at risk". Concretely: warn when
head - segbuild_maxgrows past some threshold, and warn loudly if block pruning is ever enabled while segbuild is behind. - Scheduled extension, as suggested: a flag that runs the extension when the frontier falls behind by N blocks, driven from a timer rather than by hand. Given the cost is ~20 minutes and the risk is a silent dependency, a weekly timer is cheap insurance.
- Report the frontier somewhere visible —
rsk_storageStatusor the metrics port — so the gap is observable rather than discovered by readingcollected-belowduring an incident.
Why this matters beyond housekeeping
Segbuild is now the instrument the project verifies consensus with: the full Unitrie era re-executed against it, state root by state root. An instrument that silently stops covering recent history stops being able to validate recent changes — which is precisely the window where new consensus code lands.
Related: #397 (repair existing holes), #398 (reader must abort on a gap), #399 (the pre-Unitrie era), #271/#272 (block pruning, the real threat).
Activity
SDL-A1 commentedon Nov 20, 2026
Design first, as asked. The question was whether automating segbuild creation is "just copying nodes from the garbage-collected store, or requires additional marks on the nodes touched". Having read
build_segments, it is neither — the capture criterion is wrong, and that is why segments have holes.Why segments are not self-contained
build_segmentsdocuments its own intent:The mechanism is sound and the conclusion does not follow. A segment captures what its own range touched. But state written in an earlier range and still live later sits in the earlier segment — and a later segment can only resolve it if blocks in its range happened to read it again.
That is exactly the pegout index. Pre-374 code wrote an index entry when it created a pegout at RSK #6,241,417, so that node landed in the segment covering #6.2M. The entry is still live in the state at #8.92M, but nothing in segment 093's range re-read it, so 093 never captured it. #374 reads it, finds nothing, and misclassifies the pegout (#397, §6.9d).
So "self-contained for its block range" holds only for state the range itself touches, which is not the same as the state the range can reach. Any long-lived, rarely-read state is missing from every segment after the one that wrote it.
Marks would not fix this: there is nothing to mark. The builder never saw those nodes at all.
Three designs
A. Seed each segment with the full live state at its start block.
Make the claim true: a segment contains the complete subtree reachable from its first block's state root, plus whatever its range writes. Self-contained by construction, no fallback, no markers, and a missing node becomes unambiguously an error (which is what #398 wants).
Cost: the live unitrie is ~925 MB (§6.6, measured by
rbtc_supply). 97 segments × that plus deltas is ~90 GB against today's 135 GB — so this is not obviously more expensive, because segments already run 684 MB–2.2 GB. Build cost is a full-state copy per segment start, which is sequential and cheap relative to the re-execution.B. Keep the fallback at read time, and stop pretending segments are self-contained.
What is implemented and proven today:
replay_ram --fallbackandreexec_all --fallbackconsult the archival trie on a miss. The whole Unitrie era verified this way: 568,032 fallback reads, 0 absent in both. Cost per worker is one extra RocksDB handle (~1,100 MB fixed, which is what caps us at 2 workers — see §6.9e).Honest about the trade: it works, it needs no rebuild, and it makes correctness depend on a second 131 GB store being present and complete. That store matched at seven probe heights but is not itself verified.
C. Repair-on-demand (what #397 did, automated).
Run with fallback, record every fallback read with its block, write those nodes back into the segment. Converges: each replay makes the segments more complete. 19 blocks and 56,709 nodes closed the known gaps in ~3 minutes.
Cheap and incremental, but it only ever fixes what some replay happened to exercise — it cannot make a segment sound for code not yet written.
Recommendation
B + C now, A when segbuild is next rebuilt.
B is already built and has verified the chain. C is already built and has closed the known holes. Together they make the instrument usable today without a 90 GB rebuild.
A is the only one that makes a segment trustworthy on its own, and it should be how the next build works — paired with #398, since a self-contained segment is precisely the condition under which "missing node" can be treated as a hard error rather than an ambiguity.
What would change my mind on A: if the live-state seed turns out much larger than 925 MB at recent heights, 97 copies stops being cheap. That is worth measuring before committing to it —
trie_censusorrbtc_supplyat a few heights would settle it.What automation needs, either way
collected-belowfinding below).collected-below = 9342320against a segbuild frontier of 9,230,008 — so 112,311 blocks of state are already swept from the node, and it does not matter, because forward replay needs blocks. What would break extension is Fully-pruned mode: prune headers and uncles alongside blocks #271 (prune headers and uncles) or Streaming client: verify headers and uncles without ever writing them to disk #272 (streaming client), neither of which has landed.rsk_storageStatus, so the gap is observable rather than found by readingcollected-belowduring an incident.Not coding any of this yet — flagging the design question as answered and the fork as A-vs-B being a real choice about whether segments must stand alone.
SDL-A1 commentedon Nov 20, 2026
Revised design: build segments live, during normal sync
Sergio's proposal, which is better than anything in my previous comment and much simpler:
This replaces segbuild-as-a-separate-replay-job with segbuild-as-a-by-product-of-syncing. Three things follow for free: there is no second job to schedule, the frontier never falls behind the head, and the pruning race in my earlier comment stops existing — the node captures state as it touches it, before anything is swept.
Most of it already exists.
--trie-backend/--trie-enginemake the backend pluggable;CachedTrieStore,CountingTrieStoreandOverlayTrieStoreare the decorator pattern to follow; andwindow_store.rsalready implements the sliding-window-and-seal behaviourbuild_segmentsrelies on. This is a new decorator plus reuse, not new machinery.One correction, and why the design still stands
Step 2 is the same capture criterion
build_segmentsalready uses — its own doc says "everything read or written lands in the newest table". So the hole of #397 recurs in principle: a node written at #6.2M and still live at #8.92M lands in the segment covering #8.92M only if something in that range reads it.What changes is who builds the segment. The holes exist because the segments were sealed by pre-374 code that never read the pegout index. A production node building them live runs current code, which does read it, and therefore captures it.
So the guarantee becomes: a segment is complete for the code that sealed it. The residual risk narrows to code newer than that node. That is irreducible without seeding the full live state per segment (option A in the previous comment), and it composes well with #398 — a miss then means exactly "the reading code is newer than this segment", which is an actionable message rather than the ambiguity that cost us a night.
What the implementation has to decide
1. Read amplification, and it lands on the production node. Avoiding re-writes of nodes the segment already holds needs a membership check per read: one extra read, plus a write on miss. At the 1,235–5,700 node reads per block measured in §6.9b that is the dominant cost. The node currently sustains ~55 blk/s syncing. Measure before enabling by default, and keep it opt-in (
--segbuild-out <dir>) until the number is known.2. Sealing must land on a block boundary.
build_segmentsseals by size (seal-mb). A segment namedNNN-start-endwhose contents stop mid-block is worse than no segment, because the name asserts a range it does not cover.3. Crash safety. A half-sealed segment after an unclean stop must be resumable or discarded, never kept as though complete. This is the same class of defect as #377.
4. Provenance, which is the uncomfortable part. This makes the node's own correctness the segment's provenance: a consensus bug in the node is encoded into the segment, and every later replay against it agrees. §8 already says this of recorded roots —
— and it applies here. Live-built segments are an excellent regression instrument and not an independent check. Worth stating in the docs next to the tool, so nobody later mistakes "the chain replays clean against segbuild" for "the chain is right".
5. Backfill is still needed. This covers blocks from when it is switched on. The 192,650 blocks between segbuild's frontier (#9,230,008) and the head still want the one-off forward replay, which needs blocks and not trie.
Plan
--segbuild-out <dir>, writing through on write and on read-miss, sealing by size at block boundaries;--fallbackas the safety net rather than removing it, since it costs nothing when the segment is complete;