perf(p2p): randomize contact selection for RLPx connection initiation#6503
Closed
azteca1998 wants to merge 1 commit intofix/kademlia-snapsync-peer-pruningfrom
Closed
perf(p2p): randomize contact selection for RLPx connection initiation#6503azteca1998 wants to merge 1 commit intofix/kademlia-snapsync-peer-pruningfrom
azteca1998 wants to merge 1 commit intofix/kademlia-snapsync-peer-pruningfrom
Conversation
Replace sequential bucket traversal (0→255) in get_contact_to_initiate with random selection across all eligible contacts. The sequential approach was biased toward sparse low-numbered buckets, wasting connection attempts before reaching the dense high-numbered buckets (253-255) where ~87% of contacts cluster due to XOR distance distribution.
Lines of code reportTotal lines added: Detailed view |
3 tasks
Contributor
Author
|
Superseded by #6511 (Kademlia v2) — randomized selection replaced by O(1) random index probe. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_contact_to_initiateto avoid sequential bucket traversal biasBuilds on #6497 (peer pruning fix).
Problem
After #6458 introduced the Kademlia k-bucket routing table, snap sync times regressed (~50-75% slower across hoodi, sepolia, mainnet). Part of the slowdown comes from
do_get_contact_to_initiateiterating buckets sequentially from 0→255. Due to XOR distance distribution, ~87% of contacts cluster in buckets 253-255, while buckets 0-200 are nearly empty. Sequential traversal wastes connection attempts on sparse low-numbered buckets before reaching the dense high-numbered ones where most peers live.Changes
Replace the sequential
for bucket in &self.bucketsloop with random selection from all eligible contacts across all buckets (main + replacements). This follows the same pattern already used byget_contact_for_lookupandget_contact_for_enr_lookup.Test plan