Skip to content

refactor(node): retire dead/redundant watcher surface (#1231) - #1234

Merged
thiras merged 5 commits into
mainfrom
chore/1231-retire-dead-watcher-surface
Jul 16, 2026
Merged

thiras merged 5 commits into
mainfrom
chore/1231-retire-dead-watcher-surface

Conversation

@thiras

@thiras thiras commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1231.

Two cleanups #1110/#1226 revealed, each needing a judgement call rather than a mechanical delete. Five commits, reviewable independently — the last two are self-review corrections, see § Review findings.

1. StakerSet::subscribe_changes — retired

ChainStakerSet maintained a broadcast::Sender<StakerChange> (capacity 128) and republished on every membership change. Nothing subscribed. The only call site in the repo was a unit test asserting the receiver never fires, so every send in apply_change was unconditionally a SendError — a fully-built producer pipeline with no consumer, plus a channel whose capacity rationale ("sized so a slow subscriber…") described a subscriber that did not exist.

The issue asks whether this is a planned extension point or genuinely unused. It's unused: nothing in the tree wants to react to membership changes, and the gap-is-the-bug reading would require naming the consumer that should exist. Re-add a subscription alongside the code that needs it — the trait doc now says so.

apply_change now returns bool. This is the non-obvious part: the two idempotence tests used rx.try_recv() as their observation channel, so deleting the sender would have deleted the assertion mechanism, not just a field. The bool is the mutated flag apply_change already computed internally, and it tests the property more directly than the channel did.

StakerChange survives as the internal change-representation (capacity_bond_registry still builds it, apply_change still consumes it) but moves to chain_staker_set as pub(super) — ConfigStakerSet no longer touches it, and both its producer and consumer are on the chain-backed path. It also leaves the public API (dht::mod's pub use drops it).

2. node_address_watcher_* — retired

Since #1226 collapsed the two loops into one, restarts_total / down_seconds moved in lockstep with their staker-set counterparts — one loop's health reported twice.

#1226's stated reasons for keeping it both fail:

  • "Retiring one would break existing dashboards and alerts." Nothing references it: not monitoring/grafana-dashboard.json, not monitoring/prometheus-alerts.yml, and grep -rn node_address adr/ docs/ monitoring/ is empty.
  • "Freezing down_seconds at 0 forever would be an alert that can never fire, which is worse than deleting it." This was the stronger argument — and it cut the other way. The family was gated on the bindings projection existing, so a node with pull-through off reported exactly that frozen 0. The doc argued for deletion by its own criterion.

node_address_directory_size is kept — the issue frames this as retiring "the family", but that gauge is not correlated with anything: it measures the projection's cardinality, not the loop's health, moves only on NodeRegistered/NodeDeregistered while the active set moves on all five events, and has its own tests. (An earlier revision of this description also claimed "independent producers" — that was false, every producer is the shared loop, and the claim is gone from the CHANGELOG too. The projection-vs-loop distinction carries the argument on its own.)

Falls out nicely: the bindings_live gate existed only for the deleted metrics, so it goes — and with it the reason hooks() was one function returning a pair (see § Review findings).

3. Stale observability docs

Independent of the above, and true regardless:

  • Dangling function refs. The docs attribute the paired warn! sites to watcher_loop and apply_operator_change — neither exists anywhere in the tree. Now resumable_watcher::run and RegistrySink::on_operator_change.
  • eth_newFilter-era language. "no established filters", "a healthy filter stream persists indefinitely", "a clean stream end (filter expiry / provider rotation)". There are no filters — Node event watchers hard-depend on eth_newFilter; switch to eth_getLogs polling #1106 removed them from the hot path (the default public Arbitrum Sepolia RPC rejects them with -32601). Re-anchored to the eth_getLogs poll tick.
  • Also fixes the identical stale claim on origin_directory_watcher_down_seconds (DHT: chain-backed StakerSet + OriginDirectory + alloy bindings for the on-chain fallback #651) — not this issue's family, but the same claim a few lines away in a file being cleaned for exactly that.

Review findings

A multi-agent review of the first three commits surfaced two things worth fixing here rather than deferring. Both are additions to this PR, not rewrites of it.

hooks() returned a transposable pair, and the guard test could not see it. (WatcherHook, WatcherHook) is two structurally identical boxed closures, so let (on_established, on_backoff) = hooks(&metrics) type-checks identically when reversed — and the consequence is a silent metrics inversion, with failures closing the drift window instead of opening it. bindings_live was the only reason for a combined function returning a pair, so removing the gate is what made the split available: established_hook / backoff_hook, inlined at the WatcherConfig literal, matching slash_watcher and chain_origin_directory.

The test was the sharper problem. Its down_seconds 0 assertion holds whether or not established() is ever called — down_since.elapsed() floors to 0 for the first full second — so the established leg had zero coverage while the assertion message claimed the opposite. Verified by mutation: the old test stayed green both with the pair transposed and with the hook body replaced by a no-op. Asserting on a third call fixes it, since backoff_started is edge-triggered on down_since being unset and only re-arms to 2 if established really closed the window.

Four claims in this PR's own prose were inaccurate — the same standard the docs commit applied to the appendix, turned on itself:

  • RegistryHandles said node_address_directory_size "stays absent" with pull-through off. It does not: DecdnMetrics registers as one unconditional group, so it exports a permanent 0 on every default node — indistinguishable from the collapsed-directory condition you would alert on. That is the mirror of the frozen-at-0 argument used to retire node_address_watcher_*, so the doc now states the constraint. A real fix needs a split group or labelled family; filed as follow-up.
  • The CHANGELOG's "independent producers" was false (above).
  • apply_change's bool was justified as "the only observable signal that a change was real" — it is not, staker_set_active_count is mutation-gated and a test observes realness through it. Re-anchored to the HashSet::insert/remove contract it mirrors.
  • ConfigStakerSet still described itself as what the runtime wires "until" the chain set "is ready". It shipped in feat(node): eth_getLogs resumable watcher, off eth_newFilter (#1106, #1108, #1092) #1110; every remaining construction is under #[cfg(test)].

The runbook also still scoped these metrics to the staker set "specific"ally — the framing f152fa3 re-anchored in the appendix. Post-#1226 one loop feeds both projections, and the bindings-half operator impact (missed NodeRegistered bindings leave providers unpayable and silently skipped) was deleted with the retired metric's doc and survived nowhere in the tree. Restored to the runbook, where it gets read during an incident.

Follow-ups (not this PR)

  • node_address_directory_size exports a permanent 0 when pull-through is off (pre-existing, refactor(node): one CapacityBond watcher feeding both registry projections (#1110) #1226). Needs a split metrics group or labelled family.
  • The UnbondingRequested dispatch arm has no test despite being live in the subscribed OR-set; if miswired it falls to the _ => catch-all and an unbonding operator stays active until some other event lands. Absent on main too.

Corrections to the issue text

Verification

  • cargo nextest run -p decdn-node — 807/807 pass (809 on this branch's base, minus the subscribe_changes test and one collapsed composed_hooks_*)
  • Guard test mutation-tested: it now fails with the hook pair transposed and with the established hook body neutered, and passes on correct code
  • cargo clippy --workspace --all-targets — clean
  • pre-commit run --all-files — all hooks pass, including cargo doc (which caught a public module doc linking to the now-private StakerChange) and ADR reference hygiene
  • docs/runbook.md's anchor into the ADR section still resolves — the heading is unchanged

Notes for review

  • Removing exported metrics is operator-visible even with no in-repo consumer; external scrapers can't be grepped. CHANGELOG entry added under Runtime (observability) naming the migration. Landed as its own commit so it's independently revertible.
  • StakerSet is pub, so removing a trait method is a semver break for any out-of-tree impl. In-repo only tests/dht_loopback.rs. Pre-tag, so low stakes.

Follow-up from #1110 / #1226. Second of four in the watcher-hygiene batch (#1228 → #1231 → #1227 → #1230). Independent of #1233 (#1228) — branched from main, no shared files.

🤖 Generated with Claude Code

thiras and others added 3 commits July 16, 2026 21:47
`ChainStakerSet` maintained a `broadcast::Sender<StakerChange>` and
republished on every membership change. Nothing subscribed. The only
call site of `subscribe_changes` in the repo was a unit test asserting
the receiver never fires, so every `send` in `apply_change` was
unconditionally a `SendError` — a fully-built producer pipeline with no
consumer, plus a 128-slot channel whose capacity rationale described a
slow subscriber that did not exist.

Removed: the trait method and its four impls, both `changes_tx` fields,
`CHANGES_CHANNEL_CAPACITY`, the `broadcast::channel` construction, the
send, and the test.

`apply_change` stays — it also republishes `staker_set_active_count` and
mutates the set — but now returns whether membership actually moved. The
two idempotence tests used `rx.try_recv()` as their *observation
channel*, so deleting the sender would have deleted the assertion
mechanism, not just a field. The bool is what `apply_change` already
computed internally, and it tests the same property more directly than
the channel did.

`StakerChange` survives as the internal change-representation, but moves
from `staker_set` to `chain_staker_set` as `pub(super)`: `ConfigStakerSet`
no longer touches it, and its only producer (`capacity_bond_registry`)
and only consumer (`apply_change`) are both on the chain-backed path. It
also stops being public API — `dht::mod`'s `pub use` drops it. Its doc
referenced `StakerSet::subscribe_changes`, which would have dangled.

`ConfigStakerSet` and the `dht_loopback` `AllStaked` stub both lose the
sender they held solely to satisfy the trait, and `AllStaked` collapses
to a unit struct.

The trait doc now records that the absence of a subscription seam is
deliberate, so the next reader adds one alongside a consumer rather than
ahead of one.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Since #1226 collapsed the node-address and staker-set watchers into one
`capacity-bond` loop, `decdn_node_address_watcher_{restarts_total,
down_seconds}` moved in lockstep with their staker-set counterparts —
one loop's health reported twice.

#1226 kept both deliberately, on two grounds. Both fail:

- "Retiring one would break existing dashboards and alerts." No
  dashboard, alert, ADR, or runbook in this repo has ever referenced the
  family: it appears in neither `monitoring/grafana-dashboard.json` nor
  `monitoring/prometheus-alerts.yml`, and `grep -rn node_address
  adr/ docs/ monitoring/` is empty.
- "Freezing `node_address_watcher_down_seconds` at 0 forever would be an
  alert that can never fire, which is worse than deleting it." This was
  the stronger argument, and it cut the other way — the family was gated
  on the bindings projection existing, so a pull-through-off node
  reported exactly that frozen 0.

`decdn_node_address_directory_size` is **kept**. It is not correlated
with anything: it measures the projection rather than the loop, has its
own producers in `set_binding` / `remove_binding` plus the bootstrap
seed, moves only on `NodeRegistered`/`NodeDeregistered` while the active
set moves on all five events, and has its own tests.

With the trio gone, `hooks()` loses its `bindings_live` parameter — the
gate existed only for the deleted metrics — and the two `composed_hooks_*`
tests collapse into one. `node_address_directory_size` keeps its own
independent `track_node_addresses` gate at the bootstrap site.

The replacement statement lands where `hooks` is: the capacity-bond
loop's health is `staker_set_watcher_*`, and it covers the bindings
projection because one loop feeds both.

Removing exported metrics is operator-visible even with no in-repo
consumer, so this carries a CHANGELOG entry naming the migration.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…1231)

The observability docs for the staker-set watcher family still describe
the pre-#1092/#1106/#1226 world. Two kinds of rot, both fixed here:

**Dangling function references.** `adr/appendix-observability.md` and
`metrics.rs` attribute the metrics' paired `warn!` sites to
`watcher_loop` and `apply_operator_change`. Neither function exists
anywhere in the tree. They are now `resumable_watcher::run` ("watcher RPC
error; restarting after backoff") and `capacity_bond_registry`'s
`RegistrySink::on_operator_change`.

**`eth_newFilter`-era language.** The docs describe down-seconds in terms
of "no established filters" and "a healthy filter stream persists
indefinitely", and the restart counter in terms of "a clean stream end
(filter expiry / provider rotation)". There are no filters — #1106
removed `eth_newFilter`/`eth_getFilterChanges` from the hot path (the
default public Arbitrum Sepolia RPC rejects them with -32601), and the
watchers have been `eth_getLogs` pollers since. Re-anchored to the poll
tick, and the restart counter's filter-expiry carve-out is dropped: a
poll loop has no stream to end cleanly.

The ADR section intro also now attributes the metrics to the one shared
`capacity-bond` loop, and records that they cover the bindings projection
because the same loop feeds it — which is what makes them sufficient
after #1231 retired the parallel node-address family.

Also fixes the identical "no established filters" claim on
`origin_directory_watcher_down_seconds` (#651). Not this issue's family,
but the same stale claim a few lines away in the same file; leaving it
behind in a doc block being cleaned for staleness is worse than the
original.

The `##### Active-Staker Set Watcher Metrics` heading is unchanged, so
`docs/runbook.md`'s anchor into it still resolves.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 16, 2026 18:57
@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: 8c696fcc-4bf6-4458-8caa-78b1297ca440

📥 Commits

Reviewing files that changed from the base of the PR and between 2058622 and 6148c89.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • adr/appendix-observability.md
  • crates/node/src/dht/capacity_bond_registry.rs
  • crates/node/src/dht/chain_origin_directory.rs
  • crates/node/src/dht/chain_staker_set.rs
  • crates/node/src/dht/mod.rs
  • crates/node/src/dht/staker_set.rs
  • crates/node/src/metrics.rs
  • crates/node/tests/dht_loopback.rs
  • docs/runbook.md
💤 Files with no reviewable changes (1)
  • crates/node/src/dht/chain_origin_directory.rs

Walkthrough

The PR removes StakerSet broadcast subscriptions, applies capacity-bond log changes directly to shared active and address projections, unifies watcher metrics, removes redundant node-address metrics, and updates observability documentation and outage guidance.

Changes

Shared Capacity-Bond Watcher

Layer / File(s) Summary
Projection and subscription contract
crates/node/src/dht/{staker_set.rs,chain_staker_set.rs}, crates/node/src/dht/mod.rs, crates/node/src/dht/chain_origin_directory.rs, crates/node/tests/dht_loopback.rs
StakerSet no longer exposes change subscriptions or broadcast state. apply_change returns whether membership changed, and related implementations and tests use direct cached-set access.
Shared registry sink and watcher wiring
crates/node/src/dht/capacity_bond_registry.rs
RegistrySink applies log-derived changes directly to the active set and optional bindings projection, while bootstrap wires one shared watcher with staker-set metrics.
Watcher metrics and operational guidance
crates/node/src/metrics.rs, CHANGELOG.md, adr/appendix-observability.md, docs/runbook.md
The node-address watcher metric family and tracking state are removed; shared watcher semantics, alert guidance, migration notes, and RPC outage consequences are updated.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CapacityBondWatcher
  participant RegistrySink
  participant Projections
  participant Metrics
  CapacityBondWatcher->>RegistrySink: emit capacity-bond log event
  RegistrySink->>Projections: update active set and optional bindings
  RegistrySink->>Metrics: record shared watcher metrics
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: 29535207606

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 removes unused watcher-related surfaces in decdn-node and updates observability documentation to match the current eth_getLogs-polling watcher architecture. It simplifies the DHT staker-set API by retiring the unused change-subscription seam and removes redundant node-address watcher health metrics that became perfectly correlated after the shared CapacityBond watcher refactor.

Changes:

  • Retires StakerSet::subscribe_changes and the associated broadcast plumbing; replaces the former “observable” signal in tests with an explicit apply_change -> bool mutation result.
  • Removes the redundant decdn_node_address_watcher_{restarts_total,down_seconds} metrics and the related hooks/state, leaving decdn_staker_set_watcher_* as the shared CapacityBond loop health signal.
  • Updates observability docs + inline metric docs to reference the current implementation points (resumable_watcher::run, RegistrySink::on_operator_change) and polling semantics.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/node/tests/dht_loopback.rs Drops now-removed subscribe_changes plumbing from a test stub staker set.
crates/node/src/metrics.rs Removes node-address watcher metric fields/state and updates watcher metric docs to match polling + new warn sites.
crates/node/src/dht/staker_set.rs Removes subscribe_changes from the StakerSet trait and simplifies ConfigStakerSet.
crates/node/src/dht/mod.rs Stops exporting StakerChange from the public dht module surface.
crates/node/src/dht/chain_staker_set.rs Moves StakerChange internal, removes broadcast sender, and makes apply_change return whether it mutated.
crates/node/src/dht/chain_origin_directory.rs Updates tests to match the simplified StakerSet trait (no subscription method).
crates/node/src/dht/capacity_bond_registry.rs Removes staker-change broadcast + node-address watcher hooks; uses only staker-set watcher health hooks.
CHANGELOG.md Adds an operator-facing note about removed metrics and the migration path.
adr/appendix-observability.md Fixes stale watcher/metric documentation to reference the current polling watcher and warn sites.

💡 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 removes redundant decdn_node_address_watcher_* metrics and the unused StakerChange broadcast channel mechanism. These changes simplify the codebase by consolidating observability for the shared capacity-bond loop and removing unused code paths. Documentation and tests have been updated to reflect these removals. 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.12% (was 80.96%, ▲ +0.17%) — 48406/59669 lines

File Coverage Lines Δ
crates/node/src/dht/capacity_bond_registry.rs 65.31% 256/392 ▼ 2.13%
crates/node/src/dht/chain_origin_directory.rs 70.43% 774/1099 ▲ +6.41%
crates/node/src/dht/chain_staker_set.rs 76.47% 104/136 ▲ +0.34%
crates/node/src/dht/staker_set.rs 94.00% 47/50 ▼ 1.31%
crates/node/src/metrics.rs 87.12% 1130/1297 ▼ 0.01%
History
Commit Total Δ vs base
f152fa3 80.97% ▲ +0.02%
6148c89 (HEAD) 81.12% ▲ +0.17%

thiras and others added 2 commits July 17, 2026 00:09
…1231)

Finishes the `bindings_live` removal. `hooks()` returned a positional
`(WatcherHook, WatcherHook)` of two structurally identical boxed closures —
`let (on_established, on_backoff) = hooks(&metrics)` type-checks identically
when reversed, and the consequence is a silent metrics inversion: failures
would close the drift window instead of opening it.

The `bindings_live` gate was the only reason for a combined function returning
a pair. With it gone, this matches the convention every other watcher already
uses (`slash_watcher`, `chain_origin_directory`): two named functions, inlined
at the `WatcherConfig` literal, so there is nothing to transpose.

The guard test could not see either failure. Its `down_seconds 0` assertion
holds whether or not `established()` is ever called — `down_since.elapsed()`
floors to 0 for the first full second — and the surviving `restarts_total 1`
assertion is driven solely by `backoff()`. Verified: the test stayed green both
with the tuple reversed and with the `established` hook body replaced by a
no-op, leaving that leg with zero coverage.

Asserting on a third call fixes it. `backoff_started` is edge-triggered on
`down_since` being unset, so the re-arm to 2 only counts if `established`
actually closed the window. Verified this fails on the neutered hook and on the
reversed tuple, and passes on correct code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
)

Same standard this PR applied to the observability appendix, turned on its own
prose. Each is verified against code, not restated from intent.

- `RegistryHandles` claimed `node_address_directory_size` "stays absent" with
  pull-through off. It does not: `DecdnMetrics` registers as one unconditional
  group, so the gauge exports a permanent `0` on every default node (pull-through
  is off by default) — indistinguishable from a pull-through-on node whose
  directory collapsed, which is the alert condition. This is the mirror of the
  frozen-at-0 argument used to retire `node_address_watcher_*`, so the doc now
  states the constraint instead of denying it. Making it genuinely absent needs
  a split group or labelled family; left as follow-up.

- The CHANGELOG's "has independent producers" was false — every producer is the
  shared `capacity-bond` loop. The projection-vs-loop clause is the correct and
  sufficient rationale on its own.

- `apply_change`'s bool was justified as "the only observable signal that a
  change was real". It is not: `staker_set_active_count` is republished only on
  mutation, and a test observes realness through exactly that gauge. Re-anchored
  to the `HashSet::insert`/`remove` contract it actually mirrors — a return value
  justifiable only by its tests should not exist.

- `ConfigStakerSet` described itself as what the runtime wires "until" the chain
  set "is ready". It shipped in #1110 and is wired at runtime/mod.rs:744; every
  remaining `ConfigStakerSet` construction is under `#[cfg(test)]`. Also drops
  "subscribes to", which collides with the vocabulary this PR retired — it is an
  `eth_getLogs` poll.

The runbook still scoped these metrics to the staker set "specific"ally, the
framing f152fa3 re-anchored in the appendix. Post-#1226 one loop feeds both
projections, and the operator impact of the bindings half — missed
`NodeRegistered` bindings leave providers unpayable and silently skipped — was
deleted along with the retired metric's doc and survived nowhere in the tree.
Restored where an operator reads during an incident.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit a559ea8 into main Jul 16, 2026
23 checks passed
@thiras
thiras deleted the chore/1231-retire-dead-watcher-surface branch July 16, 2026 21:22
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: dead/redundant watcher surface after #1110 — subscribe_changes and the node_address_watcher_* gauges

2 participants