Skip to content

refactor(node): shared ChainProjection<T> wrapper for the three chain-backed DHT projections #1255

Closed

Description

@thiras

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 in dht/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_hook pairs (chain_origin_directory.rs:596-605 byte-parallel to capacity_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

Risk

Medium — touches hot-path read accessors and the shared-watcher ownership in capacity_bond_registry; the projections are well-tested, so tractable.

Activity

  1. added
    prio:medium
    rust
    on Jul 17, 2026
  2. self-assigned this
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:mediumrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions