Skip to content

Decide a segbuild gap by the collection watermark, and make the builder audible - #403

Merged
SergioDemianLerner merged 3 commits into
mainfrom
segbuild/watermark-gate-and-logging
Nov 21, 2026
Merged

SergioDemianLerner merged 3 commits into
mainfrom
segbuild/watermark-gate-and-logging

Conversation

@SDL-A1

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

Copy link
Copy Markdown
Collaborator

Follow-up to #402, found by asking whether this node could actually turn the feature on. It could not: the gate #402 shipped would refuse to start here, for the wrong reason.

The gate asked the wrong question

if exec_head > set_end + args.segbuild_lag { bail!("...cannot be built...") }

That is distance from the head — the same mistake §7.3 corrects inside the builder. Distance says a range lost its protection; it does not say anything was taken. A node stopped for a week has a gap of thousands of blocks whose nodes are all still present, because nothing swept while it was down.

The mainnet node is exactly that case:

set ends at #9,420,000
executed head #9,430,745
coverage gap 10,745 blocks
collection watermark #9,342,320
seed root at #9,420,000 present

The watermark is 77,681 blocks below the gap, so every node the gap's blocks wrote is still in an unswept epoch, and the seed the build starts from is there. The gap is buildable. The old gate refused it.

So the gate now asks the store what it collected (EpochTrieStore::collected_below) and refuses only when the watermark is above the gap's first block. Same predicate the builder already uses to decide whether to attempt a range — one rule, in both places.

A buildable gap still has to be closed promptly, so SegmentBoundaries::cut_at records a boundary at the executed head during startup and the catch-up becomes a range of its own. Left to the size-driven cut it would have waited a gigabyte of writes — about a month of chain — while its collection bound went stale after four days, and the state would have been collected out from under it.

A halt was silent

segbuild_boundaries had no logging at all. halt() wrote the HALTED file; tick() returned Tick::Halted(reason) and the caller discarded it. So a reorg deeper than the lag — the most serious event this design has a rule for, the one §7 says must require a human — produced no log line, at the time or ever after. The only trace was a file nobody was told to look for.

Now:

  • error! the moment it happens, saying the node is unaffected and keeps following the chain
  • warn! once an hour while it lasts, naming the file to remove, so a node halted for a week says so in today's log
  • debug! on the other ticks, instead of 2,880 identical lines a day

A build was silent too — nothing between Building and Built, a quarter of an hour for a full segment, with no way to tell slow from stuck. There is now a progress line every 10,000 blocks carrying the rate and the sealed bytes, and the seed a range starts from is info rather than debug, because that is the decision that matters for a range built after a catch-up.

segbuild_status

Answering "is there a gap, and can it be built" took eight commands by hand, because nothing printed the executed head's number: height_peek prints its hash, so it had to be bisected out of block_info. It is two comparisons against values already on disk.

$ segbuild_status /var/lib/rustock /var/lib/rustock/segbuild
  set ends at         #9420000
  executed head       #9430745
  canonical tip       #9430745
  collected below     #9342320
  seed root at #9420000   PRESENT (0x95e61859…)
  collection bound    #9420000

Coverage gap: #9420001..#9430745 is 10745 blocks.
Buildable: the watermark (#9342320) is 77681 blocks below the gap...
The seed state root at #9420000 is present, so a build has somewhere to start.
That is the top node, not proof of the whole trie beneath it.

Read-only, takes no lock (options.read_only → no DbLock), safe against the live node. The seed probe is the part worth having: the watermark settles whether a gap's own writes survived, but not whether the build has anywhere to start — the seed was written below the watermark, so its survival depended on being live when the sweep drained. One read instead of a 10,745-block trial replay.

Verification

Storage 269, CLI bin 164 (and 164 with --features smtp), execution segment_build 4. cargo clippy -p rustock-cli -p rustock-execution --all-targets clean — it caught two bugs in this change on the way: a stray catch-all arm that shadowed the Err case so "Buildability unknown" could never print, and collapsed line-continuations that put runs of spaces inside user-facing strings.

🤖 Generated with Claude Code

SergioDemianLerner and others added 3 commits November 21, 2026 11:27
Three things, all found by asking whether this node could actually turn the
feature on.

The startup gate asked the wrong question. It refused when the executed head was
more than `--segbuild-lag` past the end of the set -- distance from the head,
which is the mistake §7.3 corrects inside the builder. Distance says a range
lost its protection; it does not say anything was taken. A node stopped for a
week has a gap of thousands of blocks whose nodes are all present, because
nothing swept while it was down. This node is exactly that case: the set ends at
#9,420,000, it has executed to #9,430,703, and the collection watermark is
#9,342,320 -- 77,681 blocks below the gap, so every node those blocks wrote is
still in an unswept epoch. The gate now asks the store what it collected instead
of inferring it from distance, and refuses only when the watermark is above the
gap's first block.

A buildable gap still needs closing promptly, so `cut_at` records a boundary at
the executed head during startup and the catch-up becomes a range of its own.
Left to the size-driven cut it would have waited a gigabyte of writes -- about a
month of chain -- while its collection bound went stale after four days, and the
state would have been collected out from under it.

`segbuild_status` answers the question in one command. It took eight to answer
by hand, because nothing printed the executed head's *number*: `height_peek`
prints its hash, so it had to be bisected out of `block_info`. The question is
two comparisons against values already on disk, and the tool prints all three
numbers, what is pending, and whether a gap is buildable.

A halt was silent, and a long build was too. `segbuild_boundaries` had no
logging at all: `halt()` wrote the HALTED file and `tick()` returned
`Tick::Halted(reason)`, which the caller discarded. So a reorg deeper than the
lag -- the most serious event this design has a rule for -- produced no log
line, at the time or ever after. It now logs at `error` the moment it happens,
reminds at `warn` once an hour for as long as it lasts, naming the file to
remove, and says nothing on the other ticks. A build also had nothing between
"Building" and "Built", a quarter of an hour of silence for a full segment, so
there is now a progress line every 10,000 blocks carrying the rate and the
sealed bytes; and the seed a range starts from is `info` rather than `debug`,
because that is the decision that matters for a range built after a catch-up.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The watermark settles whether a gap's own writes survived, but not whether
the build has anywhere to start. The seed is the state root the set's last
block declares, and it was written below the watermark, so whether it survived
depends on it having been live when the sweep drained. One read answers it, and
that read is the whole difference between deciding from an argument and
deciding from a fact -- here it is present at #9,420,000, so the 10,740-block
gap can be built.

A present root is the top node and not proof of the trie beneath it, which the
output says. If it is ever absent the message names the recourse: that
segment's own sealed store holds the verified state at its end block.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The startup boundary was recorded at the executed head, which is zero blocks
settled, so `ready` held the range for another `--segbuild-lag` blocks before
offering it -- eight hours at mainnet block time, spent waiting for state the
node already has on disk.

Cut `lag` blocks lower and the range is settled the moment it is recorded, so
the catch-up builds on the first tick. The `lag` blocks left over stay in the
open range and are absorbed by the next size-driven cut, which is where all of
them would have gone anyway.

For the mainnet node that is the difference between closing a 10,745-block gap
in about two minutes and closing it tomorrow.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@SergioDemianLerner
SergioDemianLerner merged commit 3ad48a0 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