Skip to content

feat(kad): add Behaviour::get_record_from#6475

Draft
fully-autonomous wants to merge 1 commit into
libp2p:masterfrom
FullyAutonomous:feat/kad-get-record-from
Draft

feat(kad): add Behaviour::get_record_from#6475
fully-autonomous wants to merge 1 commit into
libp2p:masterfrom
FullyAutonomous:feat/kad-get-record-from

Conversation

@fully-autonomous

Copy link
Copy Markdown

Description

Adds Behaviour::get_record_from(key, peers): a seeded GET that contacts only a
caller-supplied peer set and never expands to peers discovered mid-walk. It is the GET
counterpart of the existing Behaviour::put_record_to — where put_record_to writes to a
fixed peer set, get_record_from reads from one. The local store is consulted exactly as in
get_record (a local hit is emitted immediately as GetRecordOk::FoundRecord with peer: None).

Motivation: S/Kademlia §4.2 node-disjoint lookups require issuing d independent lookups, each
restricted to a disjoint seed group, so the paths provably never converge on a shared
intermediate node. get_record always seeds from the routing table and expands iteratively, so
this is not currently possible without forking the crate. get_record_from reuses the existing
QueryPool::add_fixed / FixedPeersIter machinery that already backs put_record_to, whose
on_success never folds in newly discovered peers — making the GET pinned by construction.

Implementation mirrors get_record exactly, substituting queries.add_fixed(peers, info) for
add_iter_closest(...). The change is purely additive: no existing method, signature, or trait
is changed, and QueryPool::add_fixed remains pub(crate).

AI Assistance Disclosure

Tools used (required — write none if no AI was used): Claude Code

Attestation (required):

  • I have read every line of this diff, understand what it does, and can explain it in review.

Notes & open questions

Two integration tests were added in protocols/kad/src/behaviour/test.rs, in the style of the
existing get_record* tests:

  • get_record_from_seeded_peer — seeding the GET with a peer that holds the record returns it.
  • get_record_from_does_not_expand_beyond_seeded_peers — the record lives on an un-seeded
    node that the querying node knows directly; seeding the GET with a different peer that lacks
    the record yields GetRecordError::NotFound and never contacts the record-holder, proving the
    query does not expand beyond the fixed set (the disjointness property the use case relies on).

Open question for maintainers: the changelog entry has been added under the unreleased 0.49.0
section; happy to move it to a different version header if you prefer.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@fully-autonomous fully-autonomous force-pushed the feat/kad-get-record-from branch from 3c4cb34 to 1be9c70 Compare June 7, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant