Repository navigation
refactor(node): split watcher CursorPolicy into CursorStart + owned Checkpoint (#1238) - #1280
Conversation
…heckpoint (#1238) Fuse-free chain-watcher config: the old `CursorPolicy` enum conflated two orthogonal axes — persistence and floor derivation — and `WatcherConfig:: seed_cursor` silently overrode the latter, leaving policy fields dead (the #1227 defect). Replace it with a `CursorStart` enum (Seeded/FromCheckpoint/HeadMinusWindow/FullReplay) plus an owned `Checkpoint`, so persistence rides inside the variants that carry a checkpoint and both dead-field shapes become unrepresentable. - Remove `seed_cursor`; each site now expresses one clear start. - Hoist the per-variant `floor` into the single `WatcherConfig::from_block` (verified equal at every site) to kill the two-source-for-one-fact footgun. - Drop the now-degenerate `NoneFallback` enum: after origin moved off the persisted-cursor floor path, settlement is the sole `FromCheckpoint` user and is always Head-fallback, so a cold `FromCheckpoint` boot anchors at head. - Behavior change: `chain_origin_directory` now rewinds its bootstrap `replay_from` by `REORG_MARGIN_BLOCKS` (new `replay_floor`/`resume_replay_floor`), closing its previous lack of across-restart shallow-reorg coverage. Pinned by a wiring test proving the durable read feeds the rewind. Convert all six watcher sites, update policy-pin/loop tests, and add variant→ resolver wiring tests for Seeded/FullReplay/HeadMinusWindow. All pub(crate), no public-API change. 848 tests pass; clippy/fmt/doc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
WalkthroughThe resumable watcher now uses ChangesCursorStart watcher migration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant WatcherBootstrap
participant CursorStart
participant CheckpointStore
participant ResumableWatcher
WatcherBootstrap->>CursorStart: configure start mode
ResumableWatcher->>CursorStart: derive initial scan floor
CursorStart->>CheckpointStore: load durable checkpoint
CheckpointStore-->>CursorStart: return persisted cursor
CursorStart-->>ResumableWatcher: return replay or window start
ResumableWatcher->>CursorStart: persist completed window
CursorStart->>CheckpointStore: save checkpoint
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the resumable watcher cursor logic by splitting the CursorPolicy enum into CursorStart and Checkpoint to separate floor-derivation and persistence concerns, thereby removing dead fields and preventing invalid configurations. Feedback was provided regarding a behavioral change mixed into this structural refactoring: adding reorg-margin coverage to the origin directory bootstrap should ideally be separated from the pure refactoring to ensure behavior preservation and ease of bisecting future regressions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Refactors the node’s chain-watcher start/persistence configuration to eliminate “configured but never read” cursor-policy fields by splitting the old fused CursorPolicy into a CursorStart (how the first tick chooses its floor) plus an owned Checkpoint (durable persistence), and hoisting the deploy-floor into WatcherConfig::from_block for all start modes.
Changes:
- Replaced
CursorPolicy/NoneFallback/WatcherConfig::seed_cursorwithCursorStart+Checkpoint, making dead-field configurations unrepresentable. - Updated all watcher construction sites to the new config shape, including seeded start sites (origin directory, capacity-bond registry) and persisted resume (settlement).
- Added/updated guardrail tests and introduced a behavior change for
chain_origin_directory: bootstrap replay now rewinds the persisted origin checkpoint byREORG_MARGIN_BLOCKS(floored at deploy block) to provide across-restart shallow-reorg coverage.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/chain_events/resumable_watcher.rs | Introduces CursorStart + Checkpoint, removes seed_cursor and NoneFallback, updates floor resolution/persistence behavior and tests. |
| crates/node/src/chain_events/backfill.rs | Updates REORG_MARGIN_BLOCKS documentation to match the new cursor-start/persistence split and origin bootstrap rewind. |
| crates/node/src/chain_events/shared_head.rs | Adjusts shared-head test wiring to the new WatcherConfig { start: CursorStart, … } shape. |
| crates/node/src/payment_settlement.rs | Migrates settlement watcher to CursorStart::FromCheckpoint with an owned Checkpoint and updates policy-pin tests/docs. |
| crates/node/src/dht/chain_origin_directory.rs | Seeds live tail via CursorStart::Seeded { persist: Some(Checkpoint) } and adds bootstrap replay-floor rewind logic + tests. |
| crates/node/src/dht/capacity_bond_registry.rs | Switches enumeration-seeded watcher start to CursorStart::Seeded { persist: None } (no durable resume). |
| crates/node/src/slash_watcher.rs | Updates watcher config to CursorStart::HeadMinusWindow, relying on WatcherConfig::from_block as the clamp floor. |
| crates/node/src/reputation_indexer.rs | Updates watcher config to CursorStart::HeadMinusWindow, relying on WatcherConfig::from_block as the clamp floor. |
| crates/node/src/blacklist_watcher.rs | Moves blacklist watcher to CursorStart::FullReplay (deploy-floor via from_block) and updates pin test accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The defensive `warn!` in `CursorStart::Seeded`'s `initial_from` arm reused the `label` field key, which everywhere else carries the watcher label — polluting log aggregation and making the line read as a watcher named after the message. Use an `invariant` key and include the seeded `at` value (per PR review). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Coverage reportTotal: 81.54% (was 81.52%, ▲ +0.03%) — 48730/59759 lines
History
|
Context
Closes #1238. The chain-watcher
CursorPolicyenum fused two orthogonal axes — persistence (durably recording a checkpoint) and floor derivation (where the first tick starts) — and a separateWatcherConfig::seed_cursorsilently overrode floor derivation, leaving policy fields dead. That's the exact "a pin on a value nothing reads" defect #1227 corrected in prose but left structurally:chain_origin_directorydeclared areorg_margin/none_fallbackit never read (and so had no across-restart shallow-reorg coverage), andcapacity_bond_registrydeclared awindow_blocks/floorit never read.This is the root of the watcher-refactor cluster — #1251 (WatcherConfig builder) and #1255 (ChainProjection wrapper) both rebase onto the new field set.
What changed
CursorPolicy→CursorStart(Seeded/FromCheckpoint/HeadMinusWindow/FullReplay) + an ownedCheckpoint. Persistence rides inside the variants that carry aCheckpoint, so a checkpoint-resuming watcher can't be configured without one and a head-deriving watcher can't declare a margin/window it never reads.seed_cursoris gone.floorinto the singleWatcherConfig::from_block(verified equal at every site), removing the two-source-for-one-fact footgun.NoneFallbackenum. After origin moved toSeeded, settlement is the soleFromCheckpointuser and always usedHead, so a coldFromCheckpointboot anchors at head; the deadFromBlockdegrade branch is gone.chain_origin_directorynow rewinds its bootstrapreplay_frombyREORG_MARGIN_BLOCKS(floored at the deploy block) viareplay_floor/resume_replay_floor, closing its previous lack of across-restart shallow-reorg coverage. The rewind lives in origin's bootstrap (not the generic watcher) because origin replays from an enumeration and seeds its live tail.All six watcher sites converted; all types
pub(crate)(no public-API change).Testing
cargo build --all-targets,cargo clippy --all-targets,cargo fmt --check,cargo doc -D warnings— clean.cargo nextest run -p decdn-node— 848 pass (was 842).resume_replay_floor_rewinds_the_persisted_origin_checkpoint) — proves the rewind engages, not just that a value is carried; plus variant→resolver wiring tests forSeeded/FullReplay/HeadMinusWindow. Policy-pin and loop tests updated.This branch was multi-agent-reviewed (correctness / tests / comments / silent-failures / type-design); all surfaced findings are addressed.
Follow-ups (out of scope)
CursorStart.🤖 Generated with Claude Code
Summary by CodeRabbit