Repository navigation
Description
TrieStore::get returns Option<Vec<u8>>, so a segbuild reader cannot tell these apart:
- the key is genuinely absent from the state — a legitimate answer the consensus rules branch on
- the node is absent from this store — the segment never captured it
Reading the second as the first is unsound, and silently so. Worse, it is asymmetric: only code that reads state the segment-builder never read can hit it, so it always looks like a regression in the newer code. That asymmetry is what made a replay of #374 look like a mainnet consensus divergence at #8,922,011 (docs/trie-segments-design.md §6.9d) — and it defeated a pre/post A/B, because the older code never performs the read at all and so is immune by construction.
A passing run of the previous version is not a control here. That is the trap to close.
What is needed
1. Segments must record negative reads. A marker for "this key was read at build time and was genuinely absent", so re-execution can distinguish a true absence from a gap. Without it, no reader can be sound on its own.
2. The reader must abort, not continue. An unmarked miss is an unknown-unknown and must stop the run — never be reported as absence.
3. The abort message must name both explanations, because the wrong one is the intuitive one:
ABORT: node <hash> not present in segment <name> while executing block #<n>
This is NOT evidence of a consensus bug in the code under test. Two
explanations, and they are not distinguishable from here:
(a) the code under test reads state the segment never captured, because
the code that BUILT this segment never read it -- an incomplete
segment, not a wrong execution;
(b) the code that built this segment was itself wrong, and the state it
captured does not match the chain.
Re-run against a complete store (--fallback /mnt/import/rustock-trie, or
the archival trie) before concluding anything about consensus.
Interim mitigation, already in place
replay_ram and reexec_all take --fallback <dir>: segment first, complete trie on miss, counted and logged with the block number. That makes the right answer available and measures the gap, but it does not enforce the distinction, and it trusts the fallback store to be complete. The markers are what make a segment trustworthy on its own.
Related: #397 (repair today's holes).
Activity
SDL-A1 commentedon Nov 20, 2026
Working through the mechanics, I think this needs no markers in the segments — and the fix is smaller and more local than the issue as filed suggests.
A node-hash lookup can never legitimately miss
TrieStore::get(hash)is not a key lookup. It is called with a hash read out of a parent node. If a parent references childH, thenHexists in the chain's state by construction — the trie is content-addressed, so there is no such thing as "that node is legitimately not there".Legitimate absence is expressed differently: the walk descends through nodes that are present and diverges from the path, returning "no value at this key". That requires no missing node at all.
So the two cases the issue wants distinguished are already distinguishable without recording anything at build time:
store.get(child_hash)returnsNoneThe only lookup where
Noneis a legitimate answer is the top-level root ("do you hold this state root?"), which is howreplay_benchalready detects an unseedable range.Where the unsoundness actually lives
crates/trie/src/node.rsconverts a store miss into absence in several places:let data = store.get(h.as_slice())?;—?on anOptionturns a missing node intoNoneNoneif let Some(data) = store.get(...)silently skips the node on a missMissingTrieNodeexists (crates/execution/src/database.rs:40) and is raised on some paths — which is why a broken shard mapping surfaced asMissingTrieNodeduring this work — but the trie walk itself does not raise it at the sites above. That asymmetry is exactly why the pegout-index gap read as a cleanin_index=falsewith no error, and why #374 appeared to break mainnet consensus.What to change
None— a missing referenced node is corruption. The signature change ripples, which is the bulk of the work, and it is in consensus-critical code so it wants the full re-execution as its regression test (now 11.3 h, 187 blk/s,--fallbackavailable).Option: "do you hold this root" is a real question with a real negative answer.Why this matters more than the repair of #397: that fixed the gaps one replay exercised. This makes any future gap announce itself instead of silently changing the answer — and the failure is asymmetric, so it will always look like a regression in whatever code is newest.
Not implemented here. It touches
crates/trieon a consensus path, and it wants its own change, review and replay rather than being folded into this investigation.SDL-A1 commentedon Nov 23, 2026
Part 1 is being dropped, and the reason is worth recording
Part 1 proposed that segments record a negative marker — "this key was read at build time and was genuinely absent" — so a reader could tell a true absence from a gap.
The marker is unnecessary. The distinction is already in the data and is being discarded.
NodeRef::resolvereturnsNonefor two different facts:and
TrieNode::findpropagates both through?as "key not found".But the two are structurally distinguishable at the moment of the miss:
NodeRef::Emptyis a genuine absence, proven by the trie itself.NodeRef::Hash(h)with a store miss can never be a genuine absence. The parent commits to that child's hash, so the node exists in the real trie. If the store does not have it, the store is incomplete. That is always a gap.So no marker is needed to tell them apart.
What this changes
Part 1's benefit is close to zero and its cost is a format change that invalidates every segment already built.
What is still being done
Parts 2 and 3 unchanged — abort on a hash-referenced node the store does not have, with a message naming both explanations — plus making the miss distinguishable where it occurs rather than inferring it afterwards.
This delivers the whole of this issue's goal on every existing segment. It is also what would have identified segment
026's gap at #3,812,411 on 2026-11-22 immediately, instead of it presenting asSTATE ROOT MISMATCHand being investigated as a consensus divergence for a day — the exact failure mode this issue was filed to prevent.Abort on a missing segment node instead of reporting it as an absence