Skip to content

DHT: chain-backed StakerSet + OriginDirectory + alloy bindings for the on-chain fallback #651

Closed

Description

@thiras

Context

PRs #646 / #647 shipped the trait abstractions (`StakerSet`, `OriginDirectory`) and file-config-driven implementations (`ConfigStakerSet`, `ConfigOriginDirectory`) for testnet bring-up. The chain-backed implementations were deferred because they depend on contracts (`PublisherRegistry`, `OriginAssignment`, `StakingRegistry.{nodeIdOf, getActiveNodes}`) that are tracked separately (see #327 for the StakingRegistry surface).

This issue is to land the chain-backed Rust impls once those contracts ship, so operators can switch from `dht.static_active_nodes` / `dht.static_origins` (TOML) to live on-chain state via RPC.

Scope

alloy bindings (`crates/incentive`)

Add `sol!` blocks for the three view interfaces consumed by ADR 022 §FIND_VALUE Flow "Origin discovery":

  • `PublisherRegistry::namespaceOf(bytes32 hash) returns (uint256[])`
  • `OriginAssignment::getOrigins(uint256 namespaceId) returns (address[])`
  • `StakingRegistry::nodeIdOf(address operator) returns (bytes32 nodeId, bool active)`
  • `StakingRegistry::getActiveNodes(uint256 offset, uint256 limit) returns (NodeInfo[])` + paged iteration

ChainStakerSet

Implements `StakerSet` by:

  • Initial `getActiveNodes()` read at startup (paged).
  • Subscribe to `Staked` / `Unstaked` / `Slashed` events and apply to the cached set.
  • Background reconciliation tick (15min default) to repair drift on missed events.
  • Exposed via `Arc` so the runtime swaps it in via the same construction site as `ConfigStakerSet`.

ChainOriginDirectory

Implements `OriginDirectory`:

  • `lookup_origins(hash)` resolves `namespaceOf(hash)` → `getOrigins(namespaceId)` → `nodeIdOf(operator)` via `Multicall3` (ADR 022 §FIND_VALUE Flow "no inter-call dependencies within a tier ... batches via the standard `Multicall3` aggregator").
  • Subscribes to `AssignmentActivated` / `AssignmentRevoked` / `DefaultOpenAllowlistUpdated` to invalidate the per-hash cache.
  • Default-open content: `getOrigins(0)` resolved on demand.

Wiring

Runtime selects between `ConfigStakerSet` and `ChainStakerSet` based on `dht.staker_source = { "config" | "chain" }` (and similarly for OriginDirectory). Default flips to "chain" once the contracts are live.

Dependencies

References

  • Trait + config impls: `crates/node/src/dht/staker_set.rs`, `crates/node/src/dht/origin.rs`
  • ADR 022 §FIND_VALUE Flow "Origin discovery"
  • ADR 003 §NodeId-to-Ethereum Binding, ADR 016 §Off-Chain Read API

Splits out from #320.

Activity

  1. self-assigned this
    on May 21, 2026
  2. added
    status:blocked
    rust
    on May 21, 2026
  3. github-actions commented on May 21, 2026

    @github-actions

    🎯 Triage report

    This is a well-scoped implementation task to land ChainStakerSet and ChainOriginDirectory — the chain-backed counterparts to the file-config implementations shipped in #646/#647. It is explicitly blocked on contract delivery (#327 for StakingRegistry, plus PublisherRegistry and OriginAssignment still needing dedicated issues). The scope is crisp: alloy sol! bindings in crates/incentive, two new impl structs in crates/node/src/dht/, and a config-key-driven runtime wiring switch.

    📊 Assessment

    Dimension Value Reasoning
    Type Task Implementation of a pre-designed component; no design discovery needed
    Labels technical, rust, blocked, prod-blocking Rust impl work; hard-blocked on upstream contracts; required for mainnet/live-chain operation
    Coding agent Needs more info Scope is well-defined in Rust, but the sol! ABI definitions can't be written until PublisherRegistry and OriginAssignment contract interfaces are finalized. Once those ABIs land, this becomes a suitable coding-agent task.

    🔗 Similar issues

    💡 Notes and suggestions

    Blocking dependencies to track:

    1. Implement on-chain CapacityBond and PaymentChannel contract integration #327 — StakingRegistry.nodeIdOf / getActiveNodes view surface. Already tracked.
    2. PublisherRegistry + OriginAssignment — the issue notes these need a dedicated contract issue; file one before assigning this to an agent or engineer.

    Implementation checklist (once ABIs are available):

    • crates/incentive: add sol! blocks for PublisherRegistry::namespaceOf, OriginAssignment::getOrigins, StakingRegistry::nodeIdOf, StakingRegistry::getActiveNodes
    • crates/node/src/dht/staker_set.rs: implement ChainStakerSet — startup page-scan, event subscriptions (Staked/Unstaked/Slashed), 15-min reconciliation tick
    • crates/node/src/dht/origin.rs: implement ChainOriginDirectory — lookup_origins via Multicall3 batching, event-driven cache invalidation (AssignmentActivated/AssignmentRevoked/DefaultOpenAllowlistUpdated), default-open (getOrigins(0)) path
    • Config schema: add dht.staker_source and dht.origin_source enum keys ("config" | "chain") — default to "config" until contracts are confirmed live
    • Runtime wiring (crates/node bring-up): swap between Config* and Chain* impls at construction site
    • Tests: mock provider + event replay for drift-repair logic; Multicall3 batching correctness

    Anti-panic reminder: all alloy call sites must return Result; no .unwrap()/.expect() per workspace Clippy policy.

    Generated by Agentic Triage for issue #651 · ● 2M · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. removed their assignment
    on May 29, 2026
  5. removed
    status:blocked
    on Jun 2, 2026
  6. self-assigned this
    on Jun 6, 2026
  7. thiras commented on Jun 10, 2026

    @thiras
    ContributorAuthor

    Completed in #830 (the chain-backed OriginDirectory + OriginAssignment/PublisherRegistry bindings half); the StakerSet/ChainStakerSet half had already shipped earlier. Both halves of #651 are now on main. Closing.

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

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions