Skip to content

refactor(node): delete the dormant confirmations knob (#1227) - #1235

Merged
thiras merged 2 commits into
mainfrom
refactor/1227-delete-confirmations
Jul 16, 2026
Merged

thiras merged 2 commits into
mainfrom
refactor/1227-delete-confirmations

Conversation

@thiras

@thiras thiras commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1227.

Problem

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. scan_upper_bound_lags_by_confirmations passed 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 confirmations blocks, 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 its 0.

Scanning to head is accepted — not proven harmless. The distinction matters and an earlier draft of this PR got it wrong (see below):

  • Re-delivery of a canonical log is covered. Every sink is idempotent under re-scan; resumable_watcher's module doc doesn't merely observe this, it requires it, because the retry and reorg-rewind paths already re-deliver.
  • An orphaned log is not covered. Idempotency makes a repeated apply cheap; a lag would prevent applying an event that never becomes canonical at all. eth_getLogs returns 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.

⚠️ On the reorg claim's grounding

appendix-l2-deployment.md has an L1-finality row but no reorg-depth row. The sequencer-reorg-shallowness claim is asserted in backfill.rs's REORG_MARGIN_BLOCKS doc 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 in chain_events. The new doc cites backfill.rs as the single place that rationale lives. If we want it ADR-grounded — and note that constant cites nothing for why 128 — 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_margin was read only by CursorPolicy::Persisted (via resolve_persisted_start), so the 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 most of its consumers is the smell; the fix is to make it unrepresentable.

It moves into the Persisted variant. 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_margin is read from inside the Persisted arm; the token is read by run for all three policies, so the same rule leaves it on WatcherConfig.

resolve_persisted_start stays 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_directory seeds its cursor from the bootstrap snapshot (seed_cursor: Some(snapshot_block)), and a seeded cursor bypasses floor derivation — run calls initial_from only 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 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:

Was Is
"The two Persisted watchers rewind reorg_margin on resume" settlement only
"Its two consumers are settlement and the origin directory" one live consumer
"inert for three of the six watchers" five of six; four passed a real 128 (audited every site — only capacity_bond passed 0)
origin test pinned reorg_margin: REORG_MARGIN_BLOCKS dropped — pinning a value nothing reads is the #1227 defect

Also 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 0 where initial_from passes it into resolve_persisted_start passed the entire 814-test suite. The pure-fn tests prove the arithmetic given a margin; the cursor_policy pins 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_margin closes it: verified by mutation — that same 0 now fails exactly that test and nothing else.

Verification

  • cargo nextest run -p decdn-node — 815/815
  • cargo clippy --workspace --all-targets, cargo fmt --check, cargo doc — clean
  • confirmations had no ADR, docs, config, or monitoring references — pure code deletion, no operator-visible surface
  • No behavior change in either commit

Follow-up

#1238 — origin's dead derivation fields are pre-existing (capacity_bond is seeded too, under HeadMinusWindow). Removing them needs CursorPolicy's persistence and floor-derivation axes split apart, which is too big for this PR; an Option wrapper would only trade an inert field for a worse cross-field invariant. That issue also covers WatcherConfig::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 WatcherConfig literals, so this must land first. Rebased onto main after #1233/#1234.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Chain event monitoring now processes the latest available block without an added confirmation delay.
    • Resuming after downtime or chain reorganizations more consistently uses persisted progress and configured recovery windows.
    • Watcher behavior and recovery rules are now applied consistently across settlement, reputation, slash, origin, and blacklist monitoring.
  • Documentation
    • Added clearer guidance on chain-tip processing, replay handling, and remaining reorganization considerations.

Copilot AI review requested due to automatic review settings July 16, 2026 19:08
@thiras thiras self-assigned this Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: f79d4993-371e-4be2-ac2d-55d4a0d98b4a

📥 Commits

Reviewing files that changed from the base of the PR and between a559ea8 and decf094.

📒 Files selected for processing (10)
  • crates/node/src/blacklist_watcher.rs
  • crates/node/src/chain_events/backfill.rs
  • crates/node/src/chain_events/mod.rs
  • crates/node/src/chain_events/resumable_watcher.rs
  • crates/node/src/chain_events/shared_head.rs
  • crates/node/src/dht/capacity_bond_registry.rs
  • crates/node/src/dht/chain_origin_directory.rs
  • crates/node/src/payment_settlement.rs
  • crates/node/src/reputation_indexer.rs
  • crates/node/src/slash_watcher.rs
💤 Files with no reviewable changes (2)
  • crates/node/src/chain_events/shared_head.rs
  • crates/node/src/dht/capacity_bond_registry.rs

Walkthrough

The resumable watcher now scans through the current chain head without confirmation lag. Reorg rewind configuration moves from WatcherConfig into CursorPolicy::Persisted, and production watcher configurations and tests are updated accordingly.

Changes

Watcher cursor migration

Layer / File(s) Summary
Head scanning and cursor policy ownership
crates/node/src/chain_events/resumable_watcher.rs, crates/node/src/chain_events/mod.rs, crates/node/src/chain_events/backfill.rs
The watcher scans [cursor, head], removes confirmation-based bounds, and derives persisted resume floors from the policy-owned reorg margin. Documentation and tests reflect the new behavior.
Production persisted cursor wiring
crates/node/src/payment_settlement.rs, crates/node/src/dht/chain_origin_directory.rs
Settlement and origin cursor policies explicitly set REORG_MARGIN_BLOCKS; related bootstrap documentation and test expectations are updated.
Watcher configuration cleanup
crates/node/src/blacklist_watcher.rs, crates/node/src/dht/capacity_bond_registry.rs, crates/node/src/reputation_indexer.rs, crates/node/src/slash_watcher.rs, crates/node/src/chain_events/shared_head.rs
Watcher configurations and the shared-head test stop setting the removed confirmation and reorg-margin fields. Imports are adjusted accordingly.

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
Loading

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.92% (2488/2798 lines)
▲ +0.00pp vs base (88.92% → 88.92%)
Run: 29539115354

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::confirmations and updated the resumable watcher loop to scan [cursor, head] directly.
  • Moved reorg_margin into CursorPolicy::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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.14% (was 81.12%, ▲ +0.01%) — 48396/59648 lines

File Coverage Lines Δ
crates/node/src/blacklist_watcher.rs 23.42% 63/269 ▲ +0.17%
crates/node/src/chain_events/backfill.rs 98.11% 52/53 ● 0.00%
crates/node/src/chain_events/mod.rs 97.70% 85/87 ● 0.00%
crates/node/src/chain_events/resumable_watcher.rs 92.86% 338/364 ▼ 0.17%
crates/node/src/chain_events/shared_head.rs 94.30% 182/193 ▼ 0.06%
crates/node/src/dht/capacity_bond_registry.rs 65.64% 256/390 ▲ +0.33%
crates/node/src/dht/chain_origin_directory.rs 70.58% 775/1098 ▲ +0.16%
crates/node/src/payment_settlement.rs 56.14% 942/1678 ▲ +0.09%
crates/node/src/reputation_indexer.rs 59.15% 307/519 ▲ +0.23%
crates/node/src/slash_watcher.rs 53.22% 124/233 ▲ +0.45%
History
Commit Total Δ vs base
3edb6db 80.97% ▲ +0.01%
85a8393 (HEAD) 81.14% ▲ +0.01%

`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]>
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]>
@thiras
thiras merged commit e9b8208 into main Jul 16, 2026
23 checks passed
@thiras
thiras deleted the refactor/1227-delete-confirmations branch July 16, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node: WatcherConfig::confirmations is wired but never engaged — a reorg guard the code advertises and never applies

2 participants