From 9ffee8f1cedb744f5e7423bd8ddcff3fb2868295 Mon Sep 17 00:00:00 2001 From: jay tseng Date: Thu, 17 Mar 2022 01:37:53 -0400 Subject: [PATCH] move the score cap check to a better place --- internal/p2p/peermanager.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/internal/p2p/peermanager.go b/internal/p2p/peermanager.go index 7c0fa6130..4044ad569 100644 --- a/internal/p2p/peermanager.go +++ b/internal/p2p/peermanager.go @@ -891,10 +891,7 @@ func (m *PeerManager) processPeerEvent(ctx context.Context, pu PeerUpdate) { case PeerStatusBad: m.store.peers[pu.NodeID].MutableScore-- case PeerStatusGood: - // The persistent peer rank won't be affected by the score update. - if m.store.peers[pu.NodeID].MutableScore < int64(MaxPeerScoreNotPersistent) { - m.store.peers[pu.NodeID].MutableScore++ - } + m.store.peers[pu.NodeID].MutableScore++ } } @@ -1287,6 +1284,9 @@ func (p *peerInfo) Score() PeerScore { } score := p.MutableScore + if score > int64(MaxPeerScoreNotPersistent) { + score = int64(MaxPeerScoreNotPersistent) + } for _, addr := range p.AddressInfo { // DialFailures is reset when dials succeed, so this @@ -1298,11 +1298,6 @@ func (p *peerInfo) Score() PeerScore { return 0 } - // sanity check, the MutableScore already has a cap. - if score >= math.MaxUint8 { - return MaxPeerScoreNotPersistent - } - return PeerScore(score) }