Repository navigation
Description
Problem
After #1110/#1226 unified the CapacityBond watcher loop (one RegistrySink feeding both staker-set and address-binding projections), the three chain-backed DHT projections still each hand-roll the same projection wrapper scaffolding:
- poison-tolerant RwLock accessors:
read_cache/write_cache(crates/node/src/dht/chain_origin_directory.rs:620, 1009) ≡read_active(dht/chain_staker_set.rs:158) ≡ four inline blocks indht/node_address.rs:136-202 - gauge-on-real-mutation helpers:
apply_change(chain_staker_set.rs:183),set_binding/remove_binding(node_address.rs:165, 192),publish_authorized_count(chain_origin_directory.rs:1004) AbortOnDrop(tokio::spawn(resumable_watcher::run(...)))ownership +established_hook/backoff_hookpairs (chain_origin_directory.rs:596-605byte-parallel tocapacity_bond_registry.rs:318-327)- bootstrap = enumerate + build sink + WatcherConfig + spawn
chain_origin_directory can't share the loop instance (different contract/events: ContentClaimed etc.), but all three can share the wrapper type.
Proposed shape
A ChainProjection<T> (name TBD) owning: the RwLock'd state with poison recovery, a mutate-and-sample-gauge method that bumps only on real change, and the AbortOnDrop watcher handle. chain_staker_set / node_address / chain_origin_directory become thin typed façades over it (they're already close — from_parts at chain_staker_set.rs:123-132, node_address.rs:117-120).
~150-250 prod lines saved.
Coordination
- Design together with node: make the watcher shutdown-token invariant unrepresentable (WatcherHandle ownership inversion) #1236 (make the watcher shutdown-token invariant unrepresentable / WatcherHandle ownership inversion) — the wrapper is the natural home for the owned watcher handle, so one design should serve both.
- refactor(node): WatcherConfig builder with defaults + shared metric-hook helper across the six LogSink watchers #1251 (WatcherConfig builder) and refactor(node): split CursorPolicy's persistence and floor-derivation axes #1238 (CursorPolicy split) touch the same construction sites; land the builder first or fold it into the wrapper's bootstrap.
Risk
Medium — touches hot-path read accessors and the shared-watcher ownership in capacity_bond_registry; the projections are well-tested, so tractable.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
refactor(node): shared ChainProjection<T> wrapper + WatcherHandle shu…