Skip to content

refactor(node): split CursorPolicy's persistence and floor-derivation axes #1238

Closed

Description

@thiras

Follow-up from the #1235 review (#1227). Pre-existing since #1110 — not introduced by #1235, which corrects the docs but leaves the underlying shape.

Problem

CursorPolicy fuses two orthogonal axes:

  • Persistence — does the watcher durably record a checkpoint (store + key)?
  • Floor derivation — how does the first tick pick its scan floor?

WatcherConfig::seed_cursor is a third mechanism that silently overrides the second. run seeds cursor from it (resumable_watcher.rs:352), and initial_from is only called on the None branch (:304-306); the cursor is only ever written back as Some(..) (:311, :330) and never reset. So a seeded watcher never derives a floor, and its policy's derivation fields are dead.

seed_cursor's own doc already admits this in prose — "When set, the first tick scans from here instead of resolving the policy floor" — which is the tell: prose explaining that fields are meaningless is what #1227 was about.

Who is affected

Two of the six watchers seed their cursor:

Watcher Policy Seeded? Dead fields
payment_settlement Persisted no — (the only live reorg_margin consumer)
dht::chain_origin_directory Persisted yes (:365) none_fallback, reorg_margin
dht::capacity_bond_registry HeadMinusWindow yes (:409) window_blocks, floor
blacklist_watcher FullReplay no —
slash_watcher HeadMinusWindow no —
reputation_indexer HeadMinusWindow no —

Origin therefore declares reorg_margin: REORG_MARGIN_BLOCKS and reads it never; its real resume floor is replay_from (chain_origin_directory.rs:316-319) — the raw checkpoint with no rewind. Note this means origin has no across-restart shallow-reorg coverage today. Whether it should is a separate question worth answering (see below).

Why not fixed in #1235

Removing the dead fields is not a deletion. reorg_margin is required by the Persisted variant, so the options were:

  • Wrap the derivation fields in an Option — trades an inert field for a cross-field invariant (Persisted { derive: None } with seed_cursor: None becomes representable and wrong). Worse than today.
  • Split the axes properly — correct, but touches the shared loop and all six sites; too big for a PR titled "delete the dormant confirmations knob".

Sketch

struct WatcherConfig {
    start: CursorStart,
    persist: Option<Checkpoint>,   // store + key — orthogonal to start
    // seed_cursor: DELETED, subsumed by CursorStart::Seeded
}

enum CursorStart {
    Seeded(u64),                                        // origin, capacity_bond
    FromCheckpoint { none_fallback, reorg_margin },      // settlement
    HeadMinusWindow { window_blocks, floor },            // slash, reputation
    FullReplay { floor },                                // blacklist
}

This makes both dead-field cases unrepresentable and removes the seed_cursor/policy overlap.

Decide while doing it

  1. Should origin rewind on resume? Today it does not. If yes, that is a behavior change (widens origin's boot re-scan by REORG_MARGIN_BLOCKS) and needs its own test proving the rewind engages.
  2. WatcherConfig::from_block is the same shape. Read only via initial_from's Persisted arm (:127); the other arms read their own floor. Every site passes the same value into both, so they can silently diverge. Prefer hoisting: delete floor from the variants and let all arms read the from_block parameter — the deploy block is a contract-level fact, not a policy choice.

Guardrail

Whatever lands, pin it with a test that asserts a live production config engages the value — not one that asserts the config merely carries it. That distinction is the whole lesson of #1227: hard-coding 0 at initial_from's call site passed the entire 814-test suite before #1235 added persisted_initial_from_engages_the_configured_margin.

Activity

  1. altanoruc commented on Jul 17, 2026

    @altanoruc
    Contributor

    Triage note for a later run: two design decisions remain explicit in the issue: whether origin resume rewinds by the reorg margin, and whether from_block is hoisted out of policy variants. Please resolve both before implementation dispatch.

  2. self-assigned this
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions