Skip to content

DHT: iterative requester-side FindValue lookup (α=3 + ADR 022 §Lookup integrity filters) #649

Closed

Description

@thiras

Context

PR #647 (now landed in the #320 stack) shipped `client::find_value` — a single-shot outbound `FindValue` primitive. ADR 022 §FIND\_VALUE Flow specifies a full iterative lookup that bouncs the request through closer_nodes responses until providers are found or the lookup converges. That algorithm is deferred to this issue because it pairs more naturally with the prefetch / popularity-signals work (also deferred) than with the maintenance loop in PR #647.

Scope

Implement `DhtLookup::find_providers(hash) -> Vec` in a new `crates/node/src/dht/lookup.rs` module per ADR 022 §FIND\_VALUE Flow:

  1. Pick the α=3 closest nodes to `hash` from the local routing table.
  2. Send parallel `FindValueRequest { hash }` (via `client::find_value`) to all α nodes.
  3. Each responder returns known providers and/or closer nodes. Expand the frontier; terminate on provider hit or when no responder returns a strictly-closer node.
  4. Apply the three requester-side integrity filters in order to each response (ADR 022 §Lookup integrity):
    a. XOR distance check — drop any `closer_nodes` entry whose XOR distance to the target is not strictly less than the responder's own.
    b. Active-staker filter — drop non-staked `NodeId`s from both `closer_nodes` and `providers` (consult `StakerSet::is_active`).
    c. Negative probe cache — drop `(NodeId, hash)` pairs present in the probe cache (ADR 001 §Probe cache).
  5. Randomize the surviving provider set before returning (ADR 022 §FIND\_VALUE Flow — defense against responder ordering bias).
  6. Origin fallback — if the iterative lookup returns no providers, consult `OriginDirectory::lookup_origins(hash)` (already in place from PR feat(node): chain-backed StakerSet + bootstrap + republish + bucket refresh (PR 4/5 of #320) #647).

Acceptance criteria (selected from issue #320)

  • AC 1 — A node in a 30-node network discovers providers for a cached blob in ≤3 FIND_VALUE hops.
  • AC 2 — A node in a 500-node network discovers providers in ≤5 FIND_VALUE hops.
  • AC 12 — A `FindValueResponse` containing `closer_nodes` entries whose XOR distance is not strictly less than the responder's own has those entries dropped by the requester; honest entries from the same response are retained.
  • AC 13 — The requester randomizes the surviving provider set before issuing `cdn/probe/v1` requests; probe order is statistically independent of `FindValueResponse.providers` order.
  • AC 14 — NodeIds returning `has_blob: false` for hash H are not re-probed for H within the negative probe cache TTL (ADR 001).
  • AC 6 — During bootstrap (routing table < k entries), the on-chain origin directory provides the fallback.

Implementation notes

  • `client::find_value` and `OriginDirectory` are in place from PR feat(node): chain-backed StakerSet + bootstrap + republish + bucket refresh (PR 4/5 of #320) #647.
  • The probe cache lives in the existing probe handler — need to either expose its API or thread a shared handle.
  • Concurrent α-fan-out fits naturally with `tokio::spawn` + `tokio::select!`.
  • The "in-flight set" + "frontier set" + "queried set" bookkeeping is the trickiest part — see the iterative Kademlia pseudocode in any standard implementation.

References

  • ADR 022 §FIND\_VALUE Flow + §Lookup integrity
  • Existing primitive: `crates/node/src/dht/client.rs::find_value`
  • Existing fallback: `crates/node/src/dht/origin.rs` (`OriginDirectory` trait)

Splits out from #320 (called "PR 5 of #320" in the plan at `/home/thiras/.claude/plans/issue-320-atomic-fox.md`).

Activity

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

    @github-actions

    🎯 Triage report

    This issue tracks the iterative Kademlia FindValue lookup (α=3 fan-out) deferred from PR #647. It is a well-scoped implementation task within crates/node/src/dht/lookup.rs, building directly on the client::find_value primitive and OriginDirectory fallback already landed. The three requester-side integrity filters (XOR distance, active-staker, negative probe cache) and provider randomization are fully specified by ADR 022.

    📊 Assessment

    Dimension Value Reasoning
    Type Task Pure implementation of a specified algorithm; no design ambiguity
    Labels technical, rust, high Core DHT routing correctness; blocks AC 1/2 of the #320 milestone
    Coding agent Suitable Requirements are precise, primitives are in place, success criteria are quantitative (hop counts) and testable

    🔗 Similar issues

    💡 Notes and suggestions

    Sub-task checklist for the implementer:

    • Create crates/node/src/dht/lookup.rs with DhtLookup struct
    • Implement find_providers(hash) -> Vec<NodeId> with in-flight / frontier / queried sets
    • α=3 parallel fan-out via tokio::spawn + channel aggregation (not tokio::select! which would race-cancel siblings)
    • XOR distance integrity filter on closer_nodes entries
    • StakerSet::is_active filter on both closer_nodes and providers
    • Negative probe cache integration — expose a shared handle from the probe handler or pass via constructor
    • Provider set shuffle before return (rand::seq::SliceRandom::shuffle)
    • Origin fallback when lookup returns empty (OriginDirectory::lookup_origins)
    • Unit tests covering: convergence in a mocked 30-node graph (AC 1), XOR-filter drops (AC 12), randomization (AC 13), probe cache suppression (AC 14), bootstrap fallback (AC 6)

    Implementation notes:

    • The standard iterative Kademlia algorithm (Maymounkov & Mazières 2002) uses three disjoint sets: queried (already contacted), frontier (known but not yet contacted), in_flight (currently outstanding). Termination: no responder returns a strictly closer node AND frontier is empty.
    • Concurrency limit α=3 means at most 3 outstanding RPCs at a time, not 3 total hops — the hop-count ACs measure depth, not total RPCs.
    • The probe cache handle is the trickiest wiring point; consider a Arc<NegativeProbeCache> threaded through DhtLookup::new(...).

    Generated by Agentic Triage for issue #649 · ● 1.7M · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:highrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions