You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(node): collapse the 6 watcher backoff/cycle recorders into a second macro family #1266
Follow-up from #1247 (PR #1263), which deliberately scoped it out.
Problem
PR #1263 collapsed the 134 single-forward recorders in impl Metrics onto a recorders! table. Six hand-written survivors remain that are also mechanically identical to each other — three {slash, staker_set, origin_directory} watchers × a backoff_started / cycle_established pair.
They are out of scope for #1247 because they touch Metrics's own Mutex<Option<Instant>> fields rather than only self.decdn, so the single-forward macro cannot express them. But the three copies of each are byte-identical modulo the watcher name:
staker_set_watcher_backoff_started and origin_directory_watcher_backoff_started differ only in the two field names (one carries an extra explanatory comment). The three *_cycle_established are the same shape around *down_since = None.
encode() then hand-repeats the paired down-seconds recompute three times as well (staker_set, origin_directory, slash) — same shape, same i64::MAX-on-poisoned-lock rationale, three copies.
Each watcher therefore costs 3 hand-maintained copies of the same state machine, and the invariant that binds them (open the drift window on the None -> Some edge, count once, clear on recovery, report i64::MAX on a poisoned lock so an outage is never masked) is only enforced by copy-paste discipline.
Proposed fix
A second macro family over {watcher_ident, down_since_field, restarts_field, down_seconds_field} generating the pair plus, ideally, the encode() recompute — so adding a fourth watcher is one line rather than five edits across two functions.
Acceptance
The three watchers declare their gauges once each.
Triage note for a later run: this is small, but the issue leaves one scope decision open: must the new macro also generate the three encode() down-seconds recomputations, or only the six backoff/cycle recorders? Please make that requirement explicit before automated dispatch.
Activity
altanoruc commentedon Jul 17, 2026
Triage note for a later run: this is small, but the issue leaves one scope decision open: must the new macro also generate the three
encode()down-seconds recomputations, or only the six backoff/cycle recorders? Please make that requirement explicit before automated dispatch.refactor(node): generate the trivial metric recorders with a macro (#…
refactor(node): collapse the 6 watcher downtime recorders into a seco…