Skip to content

Discover forks by searching, not by holding unverifiable headers (#218) #219

Closed

Description

@SDL-A1

Migrated from SergioDemianLerner/rustock#219 (pull request by @SDL-A1, 2026-09-30).
Merged: yes. The commits are already in this repository's history.
Original: SergioDemianLerner/rustock#219

Closes #218.

The problem

A header whose parent this node does not hold has nothing to verify it against. It was stored anyway, and given a total difficulty derived from a parent of zero — a figure this node never established.

#215 refused such headers and stalled a mainnet node for an hour. The reasoning behind it was wrong: a node on a minority chain receives exactly this from every peer, and refusing them leaves no way back, because the node only ever asks for blocks above its own head, so the block where the two chains part is never requested and nothing ever links.

The change

Refuse, and then act. Unlinked headers become evidence, not chain: hashes and heights, per peer, never stored, never weighted, never eligible for the head. Once enough has settled, the node searches for where the two chains diverge, and everything fetched afterwards is verified normally.

The bound is a count of slots, not anything the peer supplies. A parentless header declares its own difficulty, so a proof-of-work requirement would cost an attacker only what it chose to claim. Accounting is per peer, so a flood fills only that peer's quota, and the peer that provokes a search is the one searched against and charged.

The connection-point search now gallops down from the head before bisecting. Forks are one or two blocks deep; bisecting 0..9.28M spent 23 round trips to learn that. A one-block fork now costs one request.

Three things the implementation found that the design had not

  • Pure doubling loses to bisection on a deep fork — 44 probes against 23. Capped at 512, past which the gallop hands over.
  • The bisection started at start: 0 and treated genesis as shared without ever checking. For a peer on another network that is false, and the search would report a connection point at genesis and sync against a chain sharing nothing. It now asks, and charges the peer when the answer is no. Pre-existing, and invisible while the search had only one entry point.
  • Nothing releases a disconnected peer's evidence — no disconnect event reaches the sync service at all. The structure bounds itself instead: 128 peers, 600s of silence, ~256 KB total, with eviction taking the peer heard from least recently so churn cannot displace an active reporter.

Testing

1,830 workspace tests pass. 389 in rustock-sync, 33 new.

  • The gallop is driven through the real transition function, not a restatement of it, over every fork depth 0–4,096 and, on a 9.28 M chain, every depth to 512 plus every power of two and its neighbours.
  • The store-level tests were verified failing against the previous behaviour first — including one that fails on the head assertion.
  • Bounds are tested with 10,000 churning peers and with a flood run against a steady reporter.

Note: rustock-cli's every_runtime_flag_is_configurable fails on main already (seven flags classified as neither one-shot nor configurable) and is untouched here.

Not in this change

Reconsidering every peer by advertised difficulty on discovering a fork (design §3.6). The search runs against the peer that supplied the evidence, which is safe — a wrong chain fails verification and the node retries — but not necessarily the best chain. It touches peer selection at sync start and belongs with restoring the checkpoint and sampling gate.

The progress watchdog responding to a follow-mode stall by re-entering follow mode is pre-existing and tracked separately.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions