Skip to content

fix(kademlia): neighborhood rebroadcast sends wrong peer lists - #5595

Open
gacevicljubisa wants to merge 2 commits into
masterfrom
fix/kademlia-neighborhood-rebroadcast
Open

fix(kademlia): neighborhood rebroadcast sends wrong peer lists#5595
gacevicljubisa wants to merge 2 commits into
masterfrom
fix/kademlia-neighborhood-rebroadcast

Conversation

@gacevicljubisa

Copy link
Copy Markdown
Member

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

The 15-minute neighborhood rebroadcast in the kademlia manage loop builds each
neighbor's list with append(neighbors[:i], neighbors[i+1:]...). That appends
into the backing array of the slice the loop is still ranging over, so from the
second iteration on the loop reads already-overwritten entries. With four
neighbors [a b c d] the loop actually sends:

i=0 -> a: [b c d] (neighbors is now [b c d d])
i=1 -> c: [b d d]
i=2 -> d: [b d d]
i=3 -> d: [b d d]

Only the first neighbor gets a correct list, b is never told anything, d is
told twice and told about itself, and the lists carry duplicates. Present since
#4412.

Changes:

  • Build the list with slices.Concat, which allocates a fresh slice.
  • Move the loop body into rebroadcastNeighborhood and expose it from
    export_test.go, so it can be driven without waiting fifteen minutes.
  • Add TestRebroadcastNeighborhood: connects four peers with storage radius 0,
    waits for the connect-time announces to settle, runs one rebroadcast, and
    asserts each neighbor receives exactly one message listing the other three
    and never itself. The test fails on master with "received 6 peers, want 3".

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

Comment thread pkg/topology/kademlia/kademlia_test.go Outdated
Comment thread pkg/topology/kademlia/export_test.go Outdated
@gacevicljubisa
gacevicljubisa requested a review from acud September 8, 2026 08:58
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.

4 participants