Skip to content

The sampled half of the difficulty gate is built and tested but never enabled #230

Closed

Description

@SDL-A1

Migrated from SergioDemianLerner/rustock#230 (issue by @SDL-A1, 2026-10-01).
Original: SergioDemianLerner/rustock#230

What happens

SnapConfig.checkpoint defaults to None, and nothing sets it:

/// Bounds a peer's claimed cumulative difficulty before the header walk
/// is committed to. `None` on a chain with no checkpoint, where the walk
/// simply runs as before.
pub checkpoint: Option<rustock_core::checkpoint::DifficultyCheckpoint>,

MAINNET_CHECKPOINT exists, is verified against this project's own synced node, and is used by the free half of the gate — a peer claiming more work than the checkpoint permits, at a height at or below it, never has its metadata recorded. That path is live.

The sampled half, which bounds a claim above the checkpoint, is implemented in ChainSampler and SamplingGate, tested against simulated honest, inflated and silent peers, wired into the snapshot session as Phase::SamplingClaim — and never runs, because no caller supplies a checkpoint.

What it would buy

A snapshot sync commits to roughly 25 minutes and 10 GB on the strength of a checkpoint the peer offered. Sampling a few hundred headers first turns that into a verdict up front rather than a discovery at the end.

Measured cost and tightness, from 156 real samples off the mainnet node:

spacing samples over 30k blocks slack vs work above checkpoint
192 156 13.0%
384 78 28.2%
768 39 67.5%

Against the total a peer claims — which is what the gate compares — 768-spacing bounds it to 0.44%, because the work above the checkpoint is under 1% of the cumulative total and the rest is exact.

What enabling it needs

  1. A decision on when it runs. It is per-session and costs requests, so running it on every snapshot sync is the obvious default, but it is not free.
  2. Wiring SnapConfig.checkpoint from the chain configuration, so mainnet gets MAINNET_CHECKPOINT and other chains get None and behave as today.
  3. A view on refresh. The checkpoint is Segmented-trie tooling, and a whole-chain replay that found a Bridge consensus bug #9,020,000; the cost of verifying a claim scales with the distance from the checkpoint to the tip, so it is weaker the longer it goes unrefreshed. It should be updated per release, which is a process question as much as a code one.

Context

Built in #215, reverted with it, restored in #220. The free half has been live since #220.

Activity

  1. added
    enhancement
    on Nov 13, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions