Repository navigation
refactor(node): delete the dormant confirmations knob (#1227) - #1235
Conversation
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (10)
💤 Files with no reviewable changes (2)
WalkthroughThe resumable watcher now scans through the current chain head without confirmation lag. Reorg rewind configuration moves from ChangesWatcher cursor migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SharedHead
participant ResumableWatcher
participant CursorPolicy
participant EthGetLogs
SharedHead->>ResumableWatcher: Provide current head
ResumableWatcher->>CursorPolicy: Resolve scan floor
CursorPolicy-->>ResumableWatcher: Return persisted cursor floor
ResumableWatcher->>EthGetLogs: Query logs through head
EthGetLogs-->>ResumableWatcher: Return canonical logs
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 |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.92% (2488/2798 lines) |
There was a problem hiding this comment.
Pull request overview
This PR refactors the node’s on-chain watcher configuration by removing the dormant WatcherConfig::confirmations knob (which was always configured as 0 and therefore never applied) and by making reorg_margin unrepresentable for watcher modes that don’t read it. This aligns the code with actual runtime behavior (scan-to-head) and tightens the watcher configuration surface so inert fields can’t silently persist.
Changes:
- Removed
WatcherConfig::confirmationsand updated the resumable watcher loop to scan[cursor, head]directly. - Moved
reorg_marginintoCursorPolicy::Persisted(the only policy that uses it), updating the two persisted watchers to supply it where it’s meaningful. - Updated module/docs/tests to pin “production config wiring” (e.g., persisted cursor reorg rewind) rather than testing arithmetic in isolation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/slash_watcher.rs | Drops now-removed confirmations/reorg_margin fields from watcher config construction. |
| crates/node/src/reputation_indexer.rs | Drops now-removed confirmations/reorg_margin fields from watcher config construction. |
| crates/node/src/payment_settlement.rs | Hoists scan-to-head rationale into module-level docs; moves reorg rewind into CursorPolicy::Persisted construction + pins it in tests. |
| crates/node/src/dht/chain_origin_directory.rs | Moves reorg rewind into CursorPolicy::Persisted construction + updates tests accordingly. |
| crates/node/src/dht/capacity_bond_registry.rs | Removes inert watcher-config fields from this non-persisted watcher config literal. |
| crates/node/src/chain_events/shared_head.rs | Updates test watcher config literal to match the new WatcherConfig shape. |
| crates/node/src/chain_events/resumable_watcher.rs | Removes confirmation-lag wiring, moves reorg_margin to CursorPolicy::Persisted, and updates tick logic + tests. |
| crates/node/src/chain_events/mod.rs | Adds/updates module documentation explaining the deliberate scan-to-head policy and its rationale. |
| crates/node/src/chain_events/backfill.rs | Updates REORG_MARGIN_BLOCKS documentation to match the new type-level placement/usage. |
| crates/node/src/blacklist_watcher.rs | Drops now-removed confirmations/reorg_margin fields from watcher config construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request refactors the chain event watcher configuration by removing the unused 'confirmations' field and moving the 'reorg_margin' field specifically into the 'CursorPolicy::Persisted' variant. Since all watchers were previously passing zero for confirmations, this change simplifies the configuration and clarifies that reorg rewinds are only applicable to durable, persisted cursors. I have no further feedback to provide.
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.
Coverage reportTotal: 81.14% (was 81.12%, ▲ +0.01%) — 48396/59648 lines
History
|
`WatcherConfig::confirmations` existed, was documented, and had a unit test — and all six watcher construction sites passed `0`, so `scan_upper_bound(head, 0)` always returned `head` and the guard never did anything. The field's own doc claimed a property the code did not deliver: > Confirmation lag: the scan upper bound is `head - confirmations`, so > the live tail never emits logs from the unstable chain tip. It emitted from the tip. This deletes the field, `scan_upper_bound`, and the test, and moves the rationale somewhere it applies to all six. The knob is not merely unused — a lag would be actively wrong here. It would delay channel registration by `confirmations` blocks, so a client's first request on a freshly-opened channel would be rejected as unknown. Scanning to head is safe because every sink is idempotent under re-scan (`resumable_watcher`'s module doc *requires* this, since the retry and reorg-rewind paths already re-deliver logs), and because reorgs on the target chain are shallow. That second claim is cited, not restated: `REORG_MARGIN_BLOCKS` in `backfill.rs` carries the Arbitrum-Sepolia-class sizing rationale and is the only place it lives — `appendix-l2-deployment` has an L1-finality row but no reorg-depth row, so there is nothing to cite in `adr/` and this change does not invent one. The doc lands in `chain_events`' module doc rather than at a call site. That placement *is* the fix for the failure mode: `payment_settlement` was the only one of six sites that explained its `0`, and the other five were silent, which is how the field's claim went unchallenged. Its note is hoisted, keeping the registration-latency cost stated where it is load-bearing. Also folds in the sibling defect. `reorg_margin` was read only by `CursorPolicy::Persisted` (via `resolve_persisted_start`), so the three `HeadMinusWindow`/`FullReplay` watchers passed a real `128` into a field nothing read, and `backfill.rs` documented that inertness *in prose* — prose explaining that a field is meaningless for half its consumers is the smell. It moves into the `Persisted` variant, making the inert combination unrepresentable. The compiler confirms the scope: after the move, `REORG_MARGIN_BLOCKS` is unused in exactly the three watchers that were passing it inertly. Same commit, because both halves rewrite the same six struct literals. `resolve_persisted_start` stays pure and unchanged, and all seven of its tests are untouched — the arithmetic was never the problem. Testing: the headline change is a deletion, and that is the result. `scan_upper_bound_lags_by_confirmations` passed for this bug's entire life because it asserted `scan_upper_bound(1_000, 12) == 988` — a value no production config ever supplied. It proved the arithmetic and merely implied the wiring. What replaces it is its inverse: the two `cursor_policy` pin tests now assert the `reorg_margin` the *production* config carries. Verified by mutation — setting it to `0` fails the test. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
3edb6db to
85a8393
Compare
Review of the confirmations deletion found that its new prose asserted a property the code does not deliver — the same defect class the PR exists to remove, re-landed one field over. `chain_origin_directory` seeds its cursor from the bootstrap snapshot (`seed_cursor: Some(snapshot_block)`), and a seeded cursor bypasses floor derivation: `run` only calls `initial_from` on the `None` branch, and the cursor is never reset to `None`. `initial_from` is the sole reader of `reorg_margin`, so origin never reads the margin it carries. Its real resume floor is `replay_from` — the raw checkpoint, no rewind. Settlement is the only live consumer. Corrected accordingly: - `chain_events`: "the two Persisted watchers rewind" -> settlement only. - `backfill`: "its two consumers" -> one live consumer; origin's is inert. - `resumable_watcher`: "inert for three of the six" -> five of six, four of which passed a real 128. Audited every site: only capacity_bond passed 0. - `chain_origin_directory`: state that neither `none_fallback` nor `reorg_margin` is read there, and drop the test pin on the margin — pinning a value nothing reads is the #1227 defect, not a guard against it. Also rewrites the module doc's safety argument, which equated sink idempotency with a confirmation lag. They are different properties: idempotency makes a repeated apply cheap; a lag prevents applying an event that never becomes canonical. `eth_getLogs` returns only canonical logs, so no sink sees a removal or has an un-apply path. That residual is real and accepted (shallow/rare reorgs; enumeration-backed sinks self-heal), not solved — and it predates this PR, since deleting an always-zero field cannot change what a lag never did. Adds the missing wiring test. The margin's use site was uncovered: hard-coding `0` where `initial_from` passes it to `resolve_persisted_start` passed the whole suite. The pure-fn tests prove the arithmetic and the cursor_policy pins prove the config carries 128; neither proved the two are connected. Origin's dead derivation fields are pre-existing and need `CursorPolicy`'s persistence and floor-derivation axes split apart to remove (capacity_bond is seeded too, under `HeadMinusWindow`) — filed separately, not done here to keep this a pure refactor with no behavior change. No behavior change. 815/815 node tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #1227.
Problem
WatcherConfig::confirmationsexisted, was documented, and had a unit test — and all six watcher construction sites passed0, soscan_upper_bound(head, 0)always returnedheadand the guard never did anything. The field's own doc claimed a property the code did not deliver:It emitted from the tip.
scan_upper_bound_lags_by_confirmationspassed for the bug's entire life because it tested the pure function directly, not any live configuration.Decision: delete
The issue offers delete-vs-wire and leans delete. Delete is right, and for a stronger reason than "Arbitrum doesn't need it" — a lag would be actively wrong for settlement. It would delay channel registration by
confirmationsblocks, so a client's first request on a freshly-opened channel would be rejected as unknown. That was the substance of the one site (payment_settlement) that bothered to explain its0.Scanning to head is accepted — not proven harmless. The distinction matters and an earlier draft of this PR got it wrong (see below):
resumable_watcher's module doc doesn't merely observe this, it requires it, because the retry and reorg-rewind paths already re-deliver.eth_getLogsreturns only canonical logs, so no sink observes a removal or has an un-apply path. This residual is accepted because reorgs on an Arbitrum-Sepolia-class L2 are shallow and rare, and the enumeration-backed sinks self-heal on re-read. It predates this PR and is unchanged by it — deleting an always-zero field cannot alter what a lag never did.appendix-l2-deployment.mdhas an L1-finality row but no reorg-depth row. The sequencer-reorg-shallowness claim is asserted inbackfill.rs'sREORG_MARGIN_BLOCKSdoc and nowhere else.Per the workspace rule that
adr/is the only source of truth for protocol-level claims, I did not invent an ADR-level claim inchain_events. The new doc citesbackfill.rsas the single place that rationale lives. If we want it ADR-grounded — and note that constant cites nothing for why128— that's a separate change; flagging rather than papering over.Folded in: the sibling defect (
reorg_margin)Not in the issue, but the same defect and the same six struct literals.
reorg_marginwas read only byCursorPolicy::Persisted(viaresolve_persisted_start), so theHeadMinusWindow/FullReplaywatchers passed a real128into a field nothing read — andbackfill.rsdocumented that inertness in prose. Prose explaining that a field is meaningless for most of its consumers is the smell; the fix is to make it unrepresentable.It moves into the
Persistedvariant. The rule — and the reason it's this field and not the shutdown token (cf. #1230) — is put data in the variant that reads it.reorg_marginis read from inside thePersistedarm; the token is read byrunfor all three policies, so the same rule leaves it onWatcherConfig.resolve_persisted_startstays pure and unchanged, and all seven of its tests are untouched. The arithmetic was never the problem.Atomic on purpose: both halves rewrite the same six literals; splitting doubles the conflict surface for zero review benefit.
Second commit: correcting what this PR itself got wrong
Review caught this PR committing the same defect it exists to delete, one field over.
chain_origin_directoryseeds its cursor from the bootstrap snapshot (seed_cursor: Some(snapshot_block)), and a seeded cursor bypasses floor derivation —runcallsinitial_fromonly on theNonebranch, and the cursor is never reset toNone.initial_fromis the sole reader ofreorg_margin, so origin never reads the margin it carries; its real resume floor isreplay_from, the raw checkpoint with no rewind. Settlement is the only live consumer.The first commit had written three false claims and a vacuous test on top of that:
Persistedwatchers rewindreorg_marginon resume"capacity_bondpassed0)reorg_margin: REORG_MARGIN_BLOCKSAlso rewrote the module doc's safety argument, which had equated sink idempotency with a confirmation lag (see "Decision" above).
Testing
The headline change in commit 1 is a deletion: removing a test that manufactured false assurance is a net gain in suite trustworthiness.
Commit 2 adds the test that was actually missing. The margin's wiring was uncovered: hard-coding
0whereinitial_frompasses it intoresolve_persisted_startpassed the entire 814-test suite. The pure-fn tests prove the arithmetic given a margin; thecursor_policypins prove the production config carries one; nothing proved the two were connected — two legs of three, the exact shape that let #1227 ship.persisted_initial_from_engages_the_configured_margincloses it: verified by mutation — that same0now fails exactly that test and nothing else.Verification
cargo nextest run -p decdn-node— 815/815cargo clippy --workspace --all-targets,cargo fmt --check,cargo doc— cleanconfirmationshad no ADR, docs, config, or monitoring references — pure code deletion, no operator-visible surfaceFollow-up
#1238 — origin's dead derivation fields are pre-existing (
capacity_bondis seeded too, underHeadMinusWindow). Removing them needsCursorPolicy's persistence and floor-derivation axes split apart, which is too big for this PR; anOptionwrapper would only trade an inert field for a worse cross-field invariant. That issue also coversWatcherConfig::from_block, which is the same shape one field over.Follow-up from #1110 / #1226 (pre-existing since #1106). Third of four in the watcher-hygiene batch (#1228 → #1231 → #1227 → #1230).
Merge order matters: #1230 rewrites these same six
WatcherConfigliterals, so this must land first. Rebased ontomainafter #1233/#1234.🤖 Generated with Claude Code
Summary by CodeRabbit