Skip to content

refactor(node): WatcherConfig builder with defaults + shared metric-hook helper across the six LogSink watchers (#1251) - #1281

Merged
thiras merged 1 commit into
mainfrom
refactor/watcher-config-builder-1251
Jul 18, 2026
Merged

thiras merged 1 commit into
mainfrom
refactor/watcher-config-builder-1251

Conversation

@thiras

@thiras thiras commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

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_tick loop semantics and the CursorStart field 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.
  • Chained const setters with_from_block() / max_backoff() / on_established() / on_backoff() cover the per-site overrides. (with_from_block, not from_block, to satisfy clippy wrong_self_convention.)

metric_hook helper (metrics.rs)

  • metric_hook(&metrics, Metrics::recorder) replaces the seven hand-rolled Box::new(move || metrics.foo()) closures. Lives in metrics.rs (not the generic loop module) so resumable_watcher stays ignorant of the concrete Metrics type, matching the WatcherHook doc's intent. The fn(&Metrics) pointer keeps call sites reading as method paths.

Sites

All six rewritten to the builder; the seven per-site *_hook fns deleted; the one test that called them (watcher_hooks_track_the_shared_loop) rewired to metric_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's poll_interval.max(1s) clamp, settlement's self-minted watcher_shutdown.clone(), and the correct from_block / CursorStart / hook wiring per site.

Testing

  • cargo fmt -- --check — clean
  • cargo clippy -p decdn-node --all-targets — clean
  • cargo nextest run -p decdn-node — 848/848 pass
  • RUSTDOCFLAGS="-D warnings" cargo doc — clean

Reviewed 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_hook doc, two self-referential setter links, a 101-col line) applied before this PR.

🤖 Generated with Claude Code

)

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]>
Copilot AI review requested due to automatic review settings July 18, 2026 00:15
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@thiras, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: a7d54e64-6bd3-414b-a147-ff95d89d3210

📥 Commits

Reviewing files that changed from the base of the PR and between 81295b3 and 4975690.

📒 Files selected for processing (8)
  • crates/node/src/blacklist_watcher.rs
  • crates/node/src/chain_events/resumable_watcher.rs
  • crates/node/src/dht/capacity_bond_registry.rs
  • crates/node/src/dht/chain_origin_directory.rs
  • crates/node/src/metrics.rs
  • crates/node/src/payment_settlement.rs
  • crates/node/src/reputation_indexer.rs
  • crates/node/src/slash_watcher.rs

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.

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 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)) -> WatcherHook to 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.

@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 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.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 81.61% (was 81.54%, ▲ +0.07%) — 48724/59704 lines

File Coverage Lines Δ
crates/node/src/blacklist_watcher.rs 24.61% 63/256 ▲ +1.01%
crates/node/src/chain_events/resumable_watcher.rs 85.98% 466/542 ▼ 6.85%
crates/node/src/dht/capacity_bond_registry.rs 66.49% 246/370 ▲ +1.35%
crates/node/src/dht/chain_origin_directory.rs 72.52% 813/1121 ▲ +1.15%
crates/node/src/metrics.rs 93.29% 834/894 ▲ +0.04%
crates/node/src/payment_settlement.rs 56.81% 943/1660 ▲ +0.48%
crates/node/src/reputation_indexer.rs 61.03% 307/503 ▲ +1.88%
crates/node/src/slash_watcher.rs 57.94% 124/214 ▲ +4.50%
History
Commit Total Δ vs base
4975690 (HEAD) 81.61% ▲ +0.07%

@thiras
thiras merged commit 32d046e into main Jul 18, 2026
22 of 24 checks passed
@thiras
thiras deleted the refactor/watcher-config-builder-1251 branch July 18, 2026 00:29
altanoruc pushed a commit that referenced this pull request Jul 18, 2026
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
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.

refactor(node): WatcherConfig builder with defaults + shared metric-hook helper across the six LogSink watchers

2 participants