Repository navigation
refactor(node): shared ChainProjection<T> wrapper + WatcherHandle shutdown ownership (#1255) (#1236) - #1282
Conversation
…wnership (#1255) (#1236) Extract the scaffolding the three chain-backed DHT projections hand-rolled into a shared ChainProjection<T> (#1255), and invert watcher-shutdown token ownership so no call site can mint an inert CancellationToken (#1236). The two dovetail: ChainProjection's watcher field is the Arc<WatcherHandle> #1236 adds. #1255 — ChainProjection<T>: - New dht/chain_projection.rs: with_read/with_write (poison-tolerant RwLock accessors, one warn! site) + mutate_gauged (republish the size gauge only on a real change, sampled under the lock) + ChainProjection<T> (bundles the Arc<RwLock<T>> state and the owned Arc<WatcherHandle>). - ChainStakerSet / ChainNodeAddressDirectory become thin facades over it; ChainOriginDirectory holds one too, its read_cache/write_cache now delegating to the shared helpers (keeping its recompute-based gauge). - Collapses five copies of the poison-recovery idiom to one, which also gained its first test coverage. #1236 — inverted watcher-shutdown ownership: - resumable_watcher::spawn(provider, cfg, make_sink) -> WatcherHandle mints the shutdown token internally; WatcherConfig loses its shutdown field; run takes the token as an explicit param (so the flush test still drives it directly). - All six LogSink watchers moved onto spawn: five ignore the token (|_| sink); blacklist uses the make_sink: FnOnce(&CancellationToken) -> S seam so its sink shares the loop's token; settlement holds the handle and cancels at its own ordering point before the channel-close deadline. - runtime drops five token mints and calls handle.shutdown() at the same load-bearing ordered positions (blacklist/origin early, origin then flushes its Origin checkpoint; capacity-bond/slash/reputation after router.shutdown). cargo clippy --all-targets, fmt, and rustdoc all clean; 850 node tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 37 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)
WalkthroughThe change replaces externally managed watcher cancellation tokens and abort-on-drop tasks with ChangesWatcher lifecycle and DHT projection
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Runtime
participant WatcherHandle
participant ResumableWatcher
participant Sink
Runtime->>ResumableWatcher: spawn(provider, config, sink factory)
ResumableWatcher-->>Runtime: return WatcherHandle
ResumableWatcher->>Sink: provide shared cancellation token
Runtime->>WatcherHandle: shutdown()
WatcherHandle->>ResumableWatcher: cancel token
ResumableWatcher->>Sink: stop processing and flush checkpoint
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.
Code Review
This pull request refactors the background chain watchers to use a new WatcherHandle and spawn pattern, making inert shutdown tokens unrepresentable and consolidating shared scaffolding for DHT projections into a new chain_projection module. Since there are no review comments, I have no feedback to provide on the review itself.
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.
There was a problem hiding this comment.
Pull request overview
Refactors the decdn-node chain watcher + DHT projection surfaces to (1) deduplicate the chain-backed projection scaffolding and (2) make graceful watcher shutdown ownership unrepresentable at call sites by moving token ownership into a returned WatcherHandle. This keeps shutdown ordering in runtime explicit while reducing repeated poison-recovery / gauge-update patterns across the DHT projections.
Changes:
- Introduce
dht::chain_projectionwith shared poison-tolerant accessors and “update gauge only on real mutation” helpers, and wrap the projections’ state + watcher ownership inChainProjection<T>. - Invert watcher shutdown ownership:
resumable_watcher::spawnmints the shutdown token internally and returns aWatcherHandle; the runtime/services now callhandle.shutdown()instead of cancelling externally-owned tokens. - Update watcher call sites (capacity bond, slash, origin directory, reputation indexer, blacklist, settlement) and extend tests to cover poison recovery and
spawntoken wiring.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/slash_watcher.rs | Switches slash watcher to WatcherHandle ownership + explicit shutdown() method. |
| crates/node/src/runtime/mod.rs | Reworks watcher construction/shutdown sequencing to use WatcherHandle instead of runtime-minted tokens; captures origin + blacklist handles for ordered shutdown. |
| crates/node/src/reputation_indexer.rs | Migrates settlement indexer watcher to WatcherHandle and adds a shutdown() entrypoint for runtime sequencing. |
| crates/node/src/payment_settlement.rs | Makes settlement watcher token owned by the service via WatcherHandle to preserve its deadline-sensitive shutdown ordering. |
| crates/node/src/dht/node_address.rs | Refactors node-address bindings projection to use shared ChainProjection and shared mutate/gauge helper. |
| crates/node/src/dht/mod.rs | Wires in new chain_projection module. |
| crates/node/src/dht/chain_staker_set.rs | Refactors staker-set projection to use ChainProjection and shared mutate/gauge helper. |
| crates/node/src/dht/chain_projection.rs | New shared projection scaffolding: poison recovery helpers, gauged mutation helper, and ChainProjection<T> wrapper + tests. |
| crates/node/src/dht/chain_origin_directory.rs | Moves origin directory cache access to shared helpers; stores watcher handle via ChainProjection and exposes it for runtime ordering. |
| crates/node/src/dht/capacity_bond_registry.rs | Updates shared capacity-bond watcher to WatcherHandle and returns it for runtime-ordered shutdown. |
| crates/node/src/chain_events/shared_head.rs | Updates tests to pass shutdown token directly to resumable_watcher::run after config field removal. |
| crates/node/src/chain_events/resumable_watcher.rs | Removes WatcherConfig.shutdown, makes run accept an explicit token, adds WatcherHandle + spawn factory, and updates tests. |
| crates/node/src/blacklist_watcher.rs | Converts blacklist watcher from async fn run into spawn -> WatcherHandle using the make_sink(&token) seam. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 81.67% (was 81.61%, ▲ +0.06%) — 48825/59782 lines
History
|
…ndle inversion Two comment blocks still described the removed `shutdown` token model (Copilot review on #1282): - runtime origin-watcher block called the cancel "unconditional / a no-op", but it is now an `Option<Arc<WatcherHandle>>` the runtime `shutdown()`s. - `ChainOriginDirectory::bootstrap` doc still required callers to pass a `shutdown` token; the watcher now mints its own via `spawn`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Two coupled
node-crate refactors, landing together.#1255 — shared
ChainProjection<T>wrapper. The three chain-backed DHTprojections each hand-rolled the same scaffolding: poison-tolerant
RwLockaccessors, a "bump the size gauge only on a real change" helper, and an owned
AbortOnDropwatcher handle. Newdht/chain_projection.rsfactors these intowith_read/with_write,mutate_gauged, andChainProjection<T>(theArc<RwLock<T>>state + the ownedArc<WatcherHandle>).ChainStakerSetandChainNodeAddressDirectorybecome thin façades;ChainOriginDirectoryholdsone too, its
read_cache/write_cachenow delegating to the shared helpers.Five copies of the poison-recovery arm collapse to one — which also gained its
first test coverage.
#1236 — inverted watcher-shutdown ownership.
resumable_watcher::spawn(...) -> WatcherHandlenow mints theCancellationTokeninternally andWatcherConfigloses its
shutdownfield, so no call site can conjure an inert token — themistake #1230 fixed by convention, made unrepresentable. All six
LogSinkwatchers moved onto
spawn:move |_| sink);make_sink: FnOnce(&CancellationToken) -> Sseam soits sink shares the loop's token (its re-scope short-circuits on shutdown);
.shutdown()at its own pointbefore the channel-close deadline.
The runtime drops five token mints and calls
handle.shutdown()at the sameload-bearing ordered positions (capacity-bond/slash/reputation deliberately
after
router.shutdown(), since the staker set gates DHT admission during drain).Testing
cargo build && cargo clippy --all-targets— clean (-D warnings)cargo fmt -- --check— cleanRUSTDOCFLAGS=-D warnings cargo doc— cleancargo nextest run -p decdn-node— 850 passed, including a newaccessors_recover_a_poisoned_lock(first poison-path coverage) and a newspawn_hands_the_sink_the_token_shutdown_cancels(pins thatspawnwires thesink and handle to one token).
sighup_signal/runtime::testsshutdown tests.Review notes
A five-agent review found the design correct (no cycle, shutdown ordering
preserved,
mutate_gauged/make_sinkfaithful, anti-panic clean). Onefollow-up worth tracking, not addressed here: blacklist moved off the runtime
JoinSetonto a detachedspawn, so a panic in its task (unlikely under theanti-panic policy) is no longer surfaced at shutdown, and it has no health
metrics — worth a follow-up to add blacklist watcher
on_backoff/on_establishedhooks for parity with the other five.
Closes #1255
Closes #1236
🤖 Generated with Claude Code
Summary by CodeRabbit
Reliability
Data Consistency
Monitoring