Repository navigation
Description
Migrated from SergioDemianLerner/rustock#218 (issue by @SDL-A1, 2026-09-29).
Original: SergioDemianLerner/rustock#218
Two related weaknesses in how a node recovers when it is on a chain its peers are not.
1. A node on a minority chain can stand still
When this node's head is at #N and the network is on a different #N, every header a peer sends names a parent this node does not hold. Observed on mainnet: a node sat at one height while the same fourteen headers arrived every five seconds, and the progress watchdog reported it correctly throughout without recovering it:
WARN No progress for 185s: Φ = (behind 13, outstanding 0, oldest 0s)
INFO Near tip (13 blocks behind), entering follow mode
outstanding 0 — nothing is in flight — and the response to being stuck in follow mode is to enter follow mode. It recovered eventually, but by accident rather than by design.
2. The fork search scans the whole chain, always
self.state = SyncState::FindingConnectionPoint {
peer: peer_id,
peer_best: metadata.best_number,
start: 0,
end: head.number,
};0..9,280,000 is ~23 probes, for a divergence that is almost always one or two blocks deep.
Design
Written up in full offline; the shape is:
Unlinked headers are evidence, not chain. A header whose parent is not held is not assembled into anything — when this node is on a fork it never requests the other chain's fork block, so such headers never link and keeping them achieves nothing. What matters is noticing that a peer offers a chain this node cannot connect to, and going to find where the two diverge.
So: count distinct unlinked headers per peer, bounded, hashes only. Enough of them triggers a connection-point search. The evidence is then discarded — the real chain is fetched again and verified normally.
Per peer rather than global, so a peer that floods fills only its own quota, cannot displace another peer's evidence, and is the one answerable for what it sent.
Probe near the head first. Gallop down — head-1, -2, -4, -8, … — then binary-search the bracket that failed. A one-block fork resolves in one or two requests instead of 23, and a genuinely ancient divergence still converges in O(log n).
Reconsider every peer on discovering a fork, not just the one that raised it — that peer is only the first to have spoken. Advertised total difficulty orders which to try first; it decides nothing, being self-declared.
A better chain is only recognisable after downloading it. Headers carry their own difficulty, never cumulative, so the comparison cannot precede the fetch. What makes the fetch safe is the fork point: from a block this node trusts, every subsequent header's difficulty is constrained by the retarget rule.
Tests
19 planned, each to be verified failing against current behaviour first. Covering fork discovery, that nothing unverified gains weight, per-peer bounds and attribution, correct blame, and the shapes that must not break it — descending arrival, siblings at one height, repeated batches, and a header that arrives unlinked and later linked.
Related
- Follow mode's only peer-relative check is a block count, and it has silently rescued four separate bugs #117 — follow mode's only peer-relative check is a block count
Activity