From af95fffef6b1688c6a6ad2f65b291761ac77ae5a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 14 Aug 2023 13:43:32 +0700 Subject: [PATCH] identify: fix sorting of observed addresses --- p2p/protocol/identify/obsaddr.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/p2p/protocol/identify/obsaddr.go b/p2p/protocol/identify/obsaddr.go index ac299a4efe..70a7eccd49 100644 --- a/p2p/protocol/identify/obsaddr.go +++ b/p2p/protocol/identify/obsaddr.go @@ -212,10 +212,13 @@ func (oas *ObservedAddrManager) filter(observedAddrs []*observedAddr) []ma.Multi for pat := range pmap { s := pmap[pat] - // We prefer inbound connection observations over outbound. - // For ties, we prefer the ones with more votes. slices.SortFunc(s, func(first, second *observedAddr) int { - if first.numInbound > second.numInbound || len(first.seenBy) > len(second.seenBy) { + // We prefer inbound connection observations over outbound. + if first.numInbound > second.numInbound { + return -1 + } + // For ties, we prefer the ones with more votes. + if first.numInbound == second.numInbound && len(first.seenBy) > len(second.seenBy) { return -1 } return 1