Skip to content

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

Closed

Description

@thiras

Problem

The watcher engine is already unified (one resumable_watcher::run driving all six LogSink impls after #1092/#1106/#1225/#1226/#1234), but each of the six construction sites still writes a ~25-line WatcherConfig struct literal where ~10 fields are constants or near-constants (max_backfill_span: MAX_BACKFILL_BLOCK_SPAN, initial_backoff: WATCHER_INITIAL_BACKOFF, max_backoff: WATCHER_MAX_BACKOFF, rpc_call_timeout: None, seed_cursor: None, from_block: 0, …):

  • reputation_indexer.rs:107
  • capacity_bond_registry.rs:387
  • payment_settlement.rs:294
  • slash_watcher.rs:154
  • blacklist_watcher.rs:234
  • chain_origin_directory.rs:344

On top of that, seven near-identical Box::new(move || metrics.xxx()) closures implement established_hook/backoff_hook/rpc_failure_hook across slash_watcher (slash_watcher.rs:218-232), capacity_bond_registry (capacity_bond_registry.rs:318-327), chain_origin_directory (chain_origin_directory.rs:596-605), and reputation_indexer (reputation_indexer.rs:141).

Proposed fix

  • WatcherConfig builder (or Default + struct-update syntax) so each site specifies only filter, cursor policy, label, and hooks.
  • A small metric_hook(metrics, |m| m.foo()) helper deduping the seven hook closures.

~100-150 prod lines. Pure construction sugar — the loop semantics in resumable_watcher.rs are untouched, and every site is already covered by its watcher tests.

Note: cursor-policy fields are being reshaped in #1238 — coordinate so the builder lands on the post-#1238 field set rather than freezing the current one.

Risk

Low.

Activity

  1. added
    rust
    prio:low
    on Jul 17, 2026
  2. self-assigned this
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:lowrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions