Repository navigation
refactor(node): WatcherConfig builder with defaults + shared metric-hook helper across the six LogSink watchers (#1251) - #1281
Conversation
) Collapse the six ~25-line `WatcherConfig { … }` struct literals to a `WatcherConfig::new(head, filter, start, poll_interval, shutdown, label)` builder that fills the constant defaults (`from_block: 0`, `max_backfill_span`, `initial_backoff`, `max_backoff`, `rpc_call_timeout: None`, both hooks unset), with chained `const` setters `with_from_block`/`max_backoff`/`on_established`/`on_backoff` for the per-site overrides. Dedup the seven `Box::new(move || metrics.foo())` hook closures into one `metric_hook(&metrics, Metrics::recorder)` helper in `metrics.rs` (kept out of the generic loop module so `resumable_watcher` stays ignorant of the concrete `Metrics` type). Delete the seven per-site `*_hook` fns and rewire the one test that used them. Pure construction sugar — `run`/`run_tick` loop semantics and the `CursorStart` field set (#1238) are untouched; every effective field value at each site is preserved (slash's `SLASH_MAX_BACKOFF`, blacklist's `poll_interval.max(1s)`, settlement's self-minted shutdown token, the per-site `from_block`/`CursorStart`/hook wiring). Verified: fmt, clippy `--all-targets`, `nextest -p decdn-node` (848 pass), and rustdoc `-D warnings` all clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 9 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 (8)
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.
Pull request overview
This PR refactors the node’s six chain-event watchers to reduce repeated WatcherConfig { … } literals and duplicated metric-hook closures, while preserving the existing resumable_watcher run-loop semantics and cursor/start behavior.
Changes:
- Added a
WatcherConfig::new(...)constructor with shared defaults plus chained setters for the few per-site overrides. - Introduced
metrics::metric_hook(&Arc<Metrics>, fn(&Metrics)) -> WatcherHookto dedupe repeated boxed “call this metric recorder” closures. - Rewrote all affected watcher wiring sites (and the one test that used the old per-site hook fns) to use the new helpers.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/chain_events/resumable_watcher.rs | Adds WatcherConfig::new and chained setters for from_block, max_backoff, and hooks. |
| crates/node/src/metrics.rs | Adds metric_hook helper to centralize watcher metric-hook closure construction. |
| crates/node/src/slash_watcher.rs | Switches to WatcherConfig::new + .with_from_block/.max_backoff/.on_* and uses metric_hook. |
| crates/node/src/reputation_indexer.rs | Switches to WatcherConfig::new and uses metric_hook for the RPC-failure backoff hook. |
| crates/node/src/payment_settlement.rs | Switches to WatcherConfig::new while preserving the watcher-owned shutdown clone behavior. |
| crates/node/src/dht/chain_origin_directory.rs | Switches to WatcherConfig::new, keeps from_block override, and uses metric_hook for hooks. |
| crates/node/src/dht/capacity_bond_registry.rs | Switches to WatcherConfig::new, uses metric_hook, and updates the shared-loop hook test accordingly. |
| crates/node/src/blacklist_watcher.rs | Switches to WatcherConfig::new, preserves poll-interval clamp and from_block override. |
💡 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 initialization of WatcherConfig across multiple blockchain event watchers by introducing a builder-like pattern with WatcherConfig::new and chained setter methods. Additionally, it introduces a centralized metric_hook helper function in metrics.rs to deduplicate metric-recording closures previously defined locally within each watcher. There are no review comments, so I have no additional 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.61% (was 81.54%, ▲ +0.07%) — 48724/59704 lines
History
|
Resolve conflict in crates/node/src/metrics.rs by keeping both additions: the new StreamDirection/StreamLabels metric-label types on this branch and the metric_hook helper introduced by #1281 on main. The two are independent top-of-module insertions after MAX_METRICS_CONNECTIONS, and the import block auto-merged cleanly. Verified after resolution: cargo build -p decdn-node, clippy -p decdn-node -p decdn-cli --all-targets -D warnings, fmt --check, and the key-rotation metric tests (lib + client_loopback lifecycle) all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01JosVn2vDZhHqiGnRXkxfQw
What
Closes #1251. Collapses the six repeated
WatcherConfig { … }struct literals and the seven near-identical metric-hook closures into shared construction sugar. Pure construction sugar —resumable_watcher::run/run_tickloop semantics and theCursorStartfield set (#1238) are untouched.Builder (
chain_events/resumable_watcher.rs)WatcherConfig::new(head, filter, start, poll_interval, shutdown, label)fills the seven fields that were constant at every site:from_block: 0,max_backfill_span,initial_backoff,max_backoff,rpc_call_timeout: None, and both hooks unset.constsetterswith_from_block()/max_backoff()/on_established()/on_backoff()cover the per-site overrides. (with_from_block, notfrom_block, to satisfy clippywrong_self_convention.)metric_hookhelper (metrics.rs)metric_hook(&metrics, Metrics::recorder)replaces the seven hand-rolledBox::new(move || metrics.foo())closures. Lives inmetrics.rs(not the generic loop module) soresumable_watcherstays ignorant of the concreteMetricstype, matching theWatcherHookdoc's intent. Thefn(&Metrics)pointer keeps call sites reading as method paths.Sites
All six rewritten to the builder; the seven per-site
*_hookfns deleted; the one test that called them (watcher_hooks_track_the_shared_loop) rewired tometric_hook. Net −14 lines despite preserving two rationale comments (capacity-bond's #1231 note relocated to its wiring site) and fixing one intra-doc link.Behaviour preservation
Every effective field value at each site is reconstructed exactly, including the deliberate per-site deviations: slash's
SLASH_MAX_BACKOFF(30s) ceiling, blacklist'spoll_interval.max(1s)clamp, settlement's self-mintedwatcher_shutdown.clone(), and the correctfrom_block/CursorStart/ hook wiring per site.Testing
cargo fmt -- --check— cleancargo clippy -p decdn-node --all-targets— cleancargo nextest run -p decdn-node— 848/848 passRUSTDOCFLAGS="-D warnings" cargo doc— cleanReviewed by the pr-review-toolkit agents (code / comments / type-design / tests): unanimous behaviour-preserving, no blocking issues. Doc-only findings (a factual error in the
metric_hookdoc, two self-referential setter links, a 101-col line) applied before this PR.🤖 Generated with Claude Code