Repository navigation
Description
Migrated from SergioDemianLerner/rustock#272 (issue by @SDL-A1, 2026-10-05).
Original: SergioDemianLerner/rustock#272
The furthest form of #271. Rather than writing history and pruning it behind the frontier, never write it: stream BlockHeadersWithUncles, verify each header and each uncle, accumulate the exact cumulative work, check for duplicate uncles, advance the frontier — and keep none of it.
Distinct from #271, which reuses the existing ingest and lets the pruner sweep closer. This is a different ingest path, and worth having only if write I/O is itself the thing to avoid. #271 should land first; this is the optimisation on top.
The hazard on restart, and how to avoid it
This client must be able to resume from where it stopped, and that is where the consensus risk is.
The uncle-reuse rule needs the uncle lists of the preceding blocks. Held only in memory, that window is empty after a restart — so the first blocks processed afterwards could reference an uncle that was already used by a block before the restart, and nothing would catch it. The same uncle's difficulty would be counted twice, and the node's view of the chain's work would diverge from the network's. That is a consensus break, not a performance problem.
Suggested fix
On shutdown, and periodically so a crash is covered too, persist the last UNCLE_GENERATION_LIMIT (7) block headers together with all the uncles they used. On restart, rebuild the in-memory window from that and carry on. Seven blocks is exactly the reach of the rule — used_uncles walks back no further — so nothing older can change a verdict, and the cost is a few kilobytes.
Periodically as well as on shutdown matters: a kill -9 or an OOM leaves no chance to flush, and this node has already been OOM-killed once mid-sync during testing.
Resume is otherwise cheap
Beyond that window, resuming needs only (height, hash, cumulative work) — about 72 bytes — because the next chunk links by parent_hash to the frontier. So discarding history does not force a restart back to genesis.
What to be careful of
- The window must be written atomically with, or before, the frontier it corresponds to. A frontier ahead of its uncle window is the same bug in a smaller interval.
- Reorgs across a restart: the persisted window describes one chain. If the node resumes onto a different one, the window has to be discarded rather than trusted, or it will reject legitimate uncles — or worse, accept ones it should not.
- Verification is unchanged. A streaming client still runs the full uncle rule (Uncles are credited with difficulty without passing the full uncle rule #269); it just does not keep the evidence afterwards.
Activity