Repository navigation
Closed
Task
Copy link
Description
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:
- Pick the α=3 closest nodes to `hash` from the local routing table.
- Send parallel `FindValueRequest { hash }` (via `client::find_value`) to all α nodes.
- 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.
- 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). - Randomize the surviving provider set before returning (ADR 022 §FIND\_VALUE Flow — defense against responder ordering bias).
- 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
github-actions commentedon May 21, 2026
🎯 Triage report
This issue tracks the iterative Kademlia
FindValuelookup (α=3 fan-out) deferred from PR #647. It is a well-scoped implementation task withincrates/node/src/dht/lookup.rs, building directly on theclient::find_valueprimitive andOriginDirectoryfallback 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
technical,rust,high🔗 Similar issues
💡 Notes and suggestions
Sub-task checklist for the implementer:
crates/node/src/dht/lookup.rswithDhtLookupstructfind_providers(hash) -> Vec<NodeId>with in-flight / frontier / queried setstokio::spawn+ channel aggregation (nottokio::select!which would race-cancel siblings)closer_nodesentriesStakerSet::is_activefilter on bothcloser_nodesandprovidersrand::seq::SliceRandom::shuffle)OriginDirectory::lookup_origins)Implementation notes:
queried(already contacted),frontier(known but not yet contacted),in_flight(currently outstanding). Termination: no responder returns a strictly closer node ANDfrontieris empty.Arc<NegativeProbeCache>threaded throughDhtLookup::new(...).