perf(p2p): add flat connection pool decoupled from Kademlia routing table#6504
Closed
azteca1998 wants to merge 2 commits intofix/kademlia-snapsync-peer-pruningfrom
Closed
perf(p2p): add flat connection pool decoupled from Kademlia routing table#6504azteca1998 wants to merge 2 commits intofix/kademlia-snapsync-peer-pruningfrom
azteca1998 wants to merge 2 commits intofix/kademlia-snapsync-peer-pruningfrom
Conversation
…able Add a separate IndexMap<H256, Node> connection pool (capacity 50K) for RLPx connection initiation, decoupled from the k-bucket routing table (which is limited to 256 × 16 = 4,096 contacts by Kademlia design). All discovered contacts are inserted into both the k-buckets (for Kademlia protocol operations like FindNode/GetClosestNodes) and the connection pool (for peer connection initiation). This restores the large candidate pool that existed before the k-bucket migration while preserving correct Kademlia routing semantics. The connection pool is: - Populated on every contact discovery (discv4, discv5, insert_if_new) - Cleaned during prune() when contacts are marked disposable - Capped at 50K entries with oldest-first eviction - Used with random selection and k-bucket state filtering
Lines of code reportTotal lines added: Detailed view |
Matches the candidate pool size used by Reth and Nethermind.
Benchmark Block Execution Results Comparison Against Main
|
Contributor
Author
|
Superseded by #6511 (Kademlia v2) which includes the connection pool + all performance fixes. |
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
Builds on #6497 (peer pruning fix). Alternative/complementary to #6503 (randomization-only approach).
Problem
The Kademlia k-bucket routing table (#6458) limits stored contacts to 256 × 16 = 4,096 by design. The old flat
IndexMapheld up to 100K. This 25x reduction in candidate pool size caused snap sync regressions of 39-75% across all networks because:Changing k-bucket sizes would break Kademlia protocol semantics, so the routing table structure can't be modified.
Approach
Decouple "routing table" from "connection candidate pool":
get_closest_nodes,get_nodes_at_distances,get_contact_for_lookup, etc.)IndexMap<H256, Node>capped at 50K, used exclusively byget_contact_to_initiatefor RLPx connection initiationAll discovered contacts are inserted into both structures. The connection pool is cleaned during
prune()and uses k-bucket state for filtering when available (unwanted, fork ID validity). Contacts only in the pool (not in k-buckets) are assumed eligible — the RLPx handshake rejects incompatible peers.Changes
connection_pool: IndexMap<H256, Node>field toPeerTableServernew_contacts,new_contact_records,insert_if_new)do_get_contact_to_initiateto draw from pool with random selectionprune()when contacts are discardedTest plan