Repository navigation
feat(node): start the rate-bounds tail at head, resync the registry periodically - #1498
Conversation
…eriodically Two watchers that already had an authoritative on-chain read, but did not lean on it. Both are steps toward the target shape — enumerate at head, follow the tail, re-read periodically as the backstop — and neither needs a contract change. **rate-bounds.** The watcher re-scanned 10,000 blocks on every boot. There was nothing for that lookback to recover: the runtime's startup `getRateBounds()` read is authoritative and already reflects every event ever emitted, so re-deriving the floor from logs below it can only reproduce a value the node holds. The tail now starts at head (`window_blocks: 0` resolves there exactly), and the hourly re-read remains the backstop for anything the tail drops. **capacity-bond registry.** This one enumerates `getActiveNodes` at boot and then follows events forever, with no way back to chain state. That gap is documented in the observability appendix: "there is no `getActiveNodes` resync after extended outage". It matters because every input after bootstrap is an event, and a missed one never surfaces as an error — `eth_getLogs` reports no removal, so an orphaned log at the unstable tip stays applied, and a tick lost to RPC backoff advances nothing but is never replayed. Until now the only repair for a drifted set was restarting the process. `RegistryChainReads` gains `full_snapshot`, and the sink re-derives both projections every 15 minutes. Build-then-swap, never clear-then-fill: the new sets are materialized before either lock is taken, so a failed read keeps the previous projections rather than emptying them — an empty staker set would make the node treat every peer as unstaked. A failure returns `Ok` (the event tail is primary; backing off the loop would stall event pickup too) but still stamps the clock, so retries follow the resync cadence rather than the seconds-scale tick. The interval is a constant, not a config knob: it is a correctness backstop rather than a tuning surface, and an operator who set it wrong would silently lose the only drift repair short of a restart. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 49 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 (2)
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 updates two chain watchers in crates/node to rely more on authoritative on-chain reads and less on historical eth_getLogs replay, reducing startup work and adding a periodic “self-healing” reconcile loop for a long-lived projection.
Changes:
- Rate-bounds watcher no longer replays a large block window on boot; it intends to start the event tail at head and keep the hourly authoritative
getRateBounds()poll as a backstop. - Capacity-bond registry watcher gains a periodic full resync that re-enumerates chain state and swaps both cached projections wholesale, to repair drift from missed/orphaned events.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/node/src/rate_bounds_watcher.rs | Removes the large boot-time backfill window and updates watcher docs/comments accordingly. |
| crates/node/src/dht/capacity_bond_registry.rs | Adds full_snapshot and a cadence-gated periodic resync to rebuild and atomically replace both registry projections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Start the tail at head — no historical scan at all. `window_blocks: 0` | ||
| // resolves to head exactly. The startup `getRateBounds()` read is the | ||
| // authoritative baseline and already folds in every past event, so a | ||
| // lookback would re-derive a value the node holds; the hourly re-read is | ||
| // the backstop for anything the tail drops. No durable cursor needed. | ||
| CursorStart::HeadMinusWindow { window_blocks: 0 }, |
Coverage reportTotal: 80.82% (was 80.79%, ▲ +0.03%) — 54818/67826 lines
History
|
…1504) Migrates the slash, buyer-reconcile, and blacklist watchers off eth_getLogs replay onto the #1497 enumeration views (enumerate at a pinned block + follow the tail + periodic re-enumeration), removes the three *_from_block config knobs (config-breaking) and the dead replay framework, and aligns ADRs 011/019/003/016 + the observability appendix. Blacklist address-liveness uses the isOriginBlacklisted||isOperatorBlacklisted union; slash appeal deadlines fold in pausedTotal. Consolidates the deferred follow-ups from #1497/#1498/#1500 so nothing is left outstanding.
…ream (#1806) * fix(node,dht): sweep the republish scheduler after a lagged commit stream The republisher schedules a blob's first DHT `Store` off the cache's `subscribe_inserts` broadcast. That channel is bounded and retains nothing it drops, so a `Lagged` receiver cannot backfill — its own API contract says a lagged consumer must force a full republish sweep. The handler only logged, leaving every hash committed inside the lag window with no DHT record until an operator restarted the node. The `Lagged` arm now re-derives the held set and seeds whatever is missing, drawing `uniform(0, 40 min)` per record so the repair costs one cold-start window rather than a burst — an immediate bulk republish is non-conforming here for the reason it is at boot. The sweep runs detached (the store walk costs one `status()` per blob) and coalesces, so repeated lags under sustained commit pressure do not stack walks. `holder_snapshot` lifts the origin-held ∪ store union out of runtime bring-up so cold start and the sweep cannot drift apart. Seeding is now idempotent: `seed_cold_start` skips an already-scheduled hash instead of pushing a second heap entry. A duplicate drained twice and bought one spurious republish per re-seed, which also affected the periodic origin rescan. Its return value counts hashes *newly* scheduled. `schedule_cold_start` is removed — it bypassed the new guarantee and nothing called it. Three counters make the window alertable, with matching `live` rows in the observability registry. Also corrects four passages that still describe the staker-set resync as a follow-up. It shipped in #1498: `RegistrySink::on_tick_complete` re-enumerates `getRegisteredNodes` every `REGISTRY_RESYNC_INTERVAL`, which is what repairs a `nodeIdOf` resolve-failure drop. A regression test pins both legs. The trigger is the cadence, not the recovery edge — no `LogSink` hook carries the poller's error state — so the corrected prose says that rather than over-claiming. Closes #1561 * fix(node,dht): re-run coalesced lag sweeps, release the slot on panic Review findings on the lag sweep, in severity order. The single-flight flag was cleared by a statement after the `await`, so a panic inside the store walk — iroh-blobs is outside the workspace anti-panic lints, and the `JoinHandle` is dropped — stranded it `true` and disabled every later sweep for the process lifetime. The counter kept climbing while the repair counter stayed flat, which the metric docs read as the healthy case: a wedge that looks like health. The slot now releases through `prune_guard::PruneGuard`, the existing RAII helper built for this exact hazard on the rate-limiter sweeps. Coalescing dropped lags instead of re-running. Each pass re-derives the held set once, at its start, so a lag observed mid-walk concerns commits that snapshot cannot contain — skipping it stranded exactly the blobs the sweep exists to recover, contradicting ADR 022 AC 20. The request is now published before the slot is claimed and the worker loops while it can consume one. `decdn_dht_republish_lag_sweeps_total` increments before the claim, so it counts lag events rather than store walks. That placement is worth keeping — it is what makes a wedged slot diagnosable — so the docstring and the ADR row say so instead. `decdn_dht_republish_sweep_failures_total` becomes `..._seed_store_walk_failures_total` and now covers the boot-time cold start, which shares one derivation with the sweep and degraded with no metric at all. A closed cache-commit channel now stops the republisher. `recv` on a closed channel resolves instantly and forever, so the old log-and- continue arm would have spun a core; the task's own `CacheEngine` clone keeps the sender alive, which is what made it unreachable. Doc corrections, all verified against the code: - The resync prose overclaimed. `reconcile_routes` skips an errored route, and a failed `full_snapshot` stamps the clock and defers a further interval — both correlated with the RPC fault that caused the drift. It shortens the window; it does not bound it. - ADR 022 said a publisher re-derives every hash it *holds*, which an origin-only node must not do. It re-derives what it *advertises*. - `HolderSnapshot` is the input to both full seeds, not to every seed — the periodic origin rescan seeds the origin half alone. - `runtime/mod.rs` cited ADR 022 AC 16 (BatchStore acks) for the cold-start seed; AC 15 is the cold-start jitter criterion. - The appendix row for `staker_set_watcher_resolve_failures_total` had drifted from its Rust twin. Tests: the idempotence test asserted `is_empty()`, which reads the `scheduled` set and cannot observe a duplicate heap entry — a mutant that pushed the entry and returned `false` passed. It now asserts heap length, and fails on that mutant. Adds a `lag_sweep` unit test pinning the reseeded count against a pre-seeded scheduler, and an origin-only policy test that runs both polarities so the assertion is a contrast rather than an absolute. * fix(node,dht): make one live schedule entry per hash a real invariant Review findings on #1806. `RepublishScheduler` tracked bare membership, but a `BinaryHeap` cannot reschedule an interior entry — so every supersede left a tombstone that a later schedule resurrected: it popped already-overdue, passed a membership-only test, and bought a spurious republish. Three call patterns reach it: a re-seed racing the eager per-insert publish, a re-seed racing the tick path's drain-then-reschedule, and `unschedule` followed by a re-seed. `scheduled` now maps each hash to the one due time that counts and `drain_due` discards any entry that disagrees, which also lets `schedule_steady` go back to an unconditional fresh draw per ADR 022 step 3. The sweep slot's release and its re-check had to be one atomic step. A request published between a worker's final check and its release was stranded: the producer saw the slot busy, the worker then exited with nothing left to consume it, and with no later lag those commits were never swept. The slot is now three-state and the release IS the compare-exchange, so it fails if a request landed first. The RAII guard covers the panic path only and is disarmed on the clean path, where a plain store would clobber a producer that had already claimed the slot. `cache_still_holds` consulted only the iroh-blobs store, so a filesystem or pinned-origin hash that was never imported was advertised at probe time via `origin_held_size` yet dropped at its first due time, publishing no `Store` at all. It has silently discarded what the cold-start seed feeds it since #1130. An origin-only node now recovers its own store-only content. The origin-held index covers enumerable origins plus present pins, and a remote S3/R2/HTTP origin deliberately does not enumerate, so an unpinned object the node owns sat in neither half of the snapshot. Stored hashes are put to `origin_probe_presence` — the same question the origin-only serve gate asks — so the snapshot advertises exactly what the node would serve. `Fault` is skipped, never admitted: a blip must not become an advertisement, and faults are not memoised. Doc corrections: the appendix paragraph still said the drift window was "bounded by that cadence", contradicting the row this PR had already corrected; a second `AC 16` reference survived at the bootstrap comment where `AC 15` belongs; and the boot-degradation warn and metric doc both claimed the loss lasted until restart, which the lag sweep now disproves. Tests: the two new invariant tests were vacuous on first writing — jitter meant the stale entry usually was not due yet, so `drain_due` broke out before reaching the check. Rebuilt to construct the exact state; both now fail against membership-only logic. Adds coverage for the origin-held due gate and for origin-only ownership recovery, and gives the stub origin a third axis so a remote origin (answers `size`, never enumerates) is modellable.
Why
Two watchers that already had an authoritative on-chain read available but did not lean on it. Both are steps toward the target shape — enumerate at head, follow the tail, re-read periodically as the backstop — and neither needs a contract change, so they land independently of #1497.
rate-bounds: stop scanning 10k blocks per boot
The watcher re-scanned
MAX_BACKFILL_BLOCK_SPAN(10,000 blocks) on every start. There is nothing for that lookback to recover: the runtime's startupgetRateBounds()read is authoritative and already reflects every event ever emitted, so re-deriving the floor from logs below it can only reproduce a value the node already holds.The tail now starts at head —
window_blocks: 0resolves to exactlyheadviaresolve_head_window_start— and the existing hourly authoritative re-read remains the backstop for anything the tail drops. The module doc already argued this ("the startup read already established the authoritative baseline"); the lookback was just never removed.capacity-bond registry: add the missing resync
This watcher enumerates
getActiveNodesat boot and then follows events forever, with no path back to chain state. That gap is documented inadr/appendix-observability.md:It matters because every input after bootstrap is an event, and a missed one never surfaces as an error:
eth_getLogsnever reports a removal, so a log orphaned by a reorg at the unstable tip stays applied;Until now the only repair for a drifted set was restarting the process.
RegistryChainReadsgainsfull_snapshot, and the sink re-derives both projections every 15 minutes inon_tick_complete.Design notes
Build-then-swap, never clear-then-fill. The new sets are fully materialized before either lock is taken for writing, so a failed read leaves the previous projections intact rather than emptying them. An empty staker set would make the node treat every peer as unstaked.
A failure returns
Okbut still stamps the clock. The event tail is the primary path and is still working; backing the whole watcher off would also stall event pickup, trading a stale set for no updates at all. Stamping only on success would retry on every watcher tick (seconds) instead of on the resync cadence — the same trap the rate-bounds sink documents.The interval is a constant, not a config knob. It is a correctness backstop rather than a tuning surface, and an operator who set it wrong (or to zero) would silently lose the only drift repair short of a restart. This also runs against the grain of the wider work, which removes three config knobs.
Poison-tolerant locking via the existing
with_writehelper, matching the rest ofdht/.Testing
2,667 tests (from 2,663),
cargo clippy --all-targets,cargo fmt --check, all pre-commit hooks.Four new tests cover the resync: that it replaces both projections wholesale (a stale entry is dropped and a missing one restored), that a failed read keeps the previous projections, that it is cadence-gated so the seconds-scale tick does not hammer the RPC with a paginated enumeration, and that a failure still stamps the clock.
Follow-up
adr/appendix-observability.md's drift paragraph becomes stale with this change. I have left it for the ADR pass that accompanies the watcher migrations, so the doc changes land as one coherent edit rather than piecemeal.Part of the wider effort to eliminate on-chain event-log replay; the contract-side enumeration views are in #1497.
🤖 Generated with Claude Code