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.
This commit is contained in:
Csaba Kiraly 2026-04-13 10:01:26 +02:00
parent d7fddf418e
commit ed3d5ab3da

View file

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