Skip to content

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

Merged
gacevicljubisa merged 2 commits into
masterfrom
fix/kademlia-neighborhood-rebroadcast
Sep 23, 2026
Merged

gacevicljubisa merged 2 commits into
masterfrom
fix/kademlia-neighborhood-rebroadcast

Conversation

@gacevicljubisa

@gacevicljubisa gacevicljubisa commented Sep 3, 2026

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 previously built each peer's broadcast list using append(neighbors[:i], neighbors[i+1:]...). Because neighbors[:i] shares the backing array of the slice being iterated over, the slice was overwritten in-place starting from the second iteration.

For example, with four neighbors [a b c d], the loop produced:

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

As a result, only the first peer received the correct list, b was skipped, d was notified twice and told about itself, and the lists contained duplicates.

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
@martinconic

Copy link
Copy Markdown
Contributor

The PR description is out of sync with the latest commit (c97300d). It still mentions exporting RebroadcastNeighborhood in export_test.go and adding TestRebroadcastNeighborhood with storage radius 0, both of which were removed in the second commit.

@gacevicljubisa
gacevicljubisa merged commit fec2755 into master Sep 23, 2026
23 of 29 checks passed
@gacevicljubisa
gacevicljubisa deleted the fix/kademlia-neighborhood-rebroadcast branch September 23, 2026 14:48
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.

5 participants