From ed3d5ab3da542abfc5c95adbc8c5ce1d2cc33dda Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 13 Apr 2026 10:01:26 +0200 Subject: [PATCH] eth: skip protection work in dropper when pools have headroom When neither the dialed nor inbound peer pool is close to capacity, every non-trusted/non-static peer is already marked do-not-drop by the pool-threshold rules in selectDoNotDrop, so the droppable set is guaranteed empty regardless of inclusion protection. Return early in that case to avoid the wasted peerStatsFunc call, per-direction split, and per-category sort in protectedPeers. --- eth/dropper.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eth/dropper.go b/eth/dropper.go index eae5344142..bf69e8f0e1 100644 --- a/eth/dropper.go +++ b/eth/dropper.go @@ -164,6 +164,14 @@ func (cm *dropper) dropRandomPeer() bool { } numDialed := len(peers) - numInbound + // Fast path: if neither pool is near capacity, every non-trusted/non-static + // peer is already do-not-drop by pool-threshold rules. No point computing + // inclusion protection. + if cm.maxDialPeers-numDialed > peerDropThreshold && + cm.maxInboundPeers-numInbound > peerDropThreshold { + return false + } + // Compute the set of inclusion-protected peers before filtering. protected := cm.protectedPeers(peers)