Repository navigation
Description
Migrated from SergioDemianLerner/rustock#220 (pull request by @SDL-A1, 2026-09-30).
Merged: yes. The commits are already in this repository's history.
Original: SergioDemianLerner/rustock#220
The independently-sound half of #215 and #216, brought back a piece at a time. The part that stalled a mainnet node — refusing an unverifiable header with no recovery path — does not return; #219 supersedes it.
Nothing here was replayed as-is. Each piece was re-reviewed against what the stall taught, and two of them were wrong.
Cumulative-difficulty checkpoints, and the sampling gate
A checkpoint states the work from genesis to a height, so nothing may claim more for that height. Unlike a hash checkpoint it has a safe failure direction: one set too high is merely weak, one set too low is contradicted by the node's own chain and reported rather than followed.
Re-verified rather than trusted. All three checkpoint fields were queried against this project's synced node over RPC and match #9,020,000 exactly. The existing test only checked the limbs against the decimals — nothing checked the decimals themselves, and a checkpoint set too low would refuse the honest chain.
Adds tests built from 156 real samples read off that node. Real difficulty swings between 6.7e21 and 8.0e21 over the sampled range, which a synthetic flat chain cannot exercise.
They also measure the bound instead of assuming it:
| spacing | samples | slack / work above checkpoint |
|---|---|---|
| 192 | 156 | 13.0% |
| 384 | 78 | 28.2% |
| 768 | 39 | 67.5% |
The 768 figure looks alarming until you notice the denominator: work above the checkpoint is under 1% of the cumulative total, the rest being exact. Against the total a peer actually claims, the bound is 0.44%. The spacing is a real trade and there is now a number behind it.
Snapshot difficulty reconciliation — and a bug in it
The walk reads every header on the way down, so summing their difficulty turns the peer's claimed cumulative difficulty into something establishable rather than accepted.
The version being restored would have refused honest peers. The walk stops at the first block this node already holds — genesis only on a fresh node. walked_difficulty is then the work of the walked segment, while the claim is cumulative from genesis. With the anchor at #768 the established work is over four times the segment walked, so an honest peer would have been judged against a ceiling a quarter of the size.
Fixed by recording the total difficulty already established at the anchor.
Chunk matching by hash and contiguity
A chunk is the answer to a specific question; a matching height does not establish that it is. #215 shipped this with no tests. There are seven here — the three describing the threat were each checked to fail against the number-only matcher, and four pin honest cases the matcher must keep accepting.
Head re-seating
A break below the head means the head is not reachable from the executed head. The node reported this every tick while execution asked for blocks across the break, failed, and retried from the same place. Correct diagnosis, no recovery.
Testing
1,887 workspace tests pass. Note: /tmp on this host is a 3.8 GB tmpfs that sits near full, which makes RocksDB tempdirs and the linker fail intermittently under cargo test --workspace. Running with TMPDIR on real disk is clean — worth knowing before reading a red run here as a regression.
Also found, not fixed here
The snapshot walk tests is_ours only at run boundaries, so it can consume a whole run and pass an anchor inside it. That costs redundant requests, not correctness.
Still not restored
Reconsidering peers by advertised difficulty on fork discovery (design §3.6), and the sampled half of the gate is wired into snap but off by default (checkpoint: None).
🤖 Generated with Claude Code
Activity