From e38d5b75475992a7747381c6515788a444704c32 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Fri, 10 Jun 2022 12:56:04 -0400 Subject: [PATCH] overflows (cherry picked from commit 4c8651026a6147af70922cc0066e384156aaa07d) --- internal/p2p/peermanager.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/p2p/peermanager.go b/internal/p2p/peermanager.go index 53e702f39..1a8ade0f6 100644 --- a/internal/p2p/peermanager.go +++ b/internal/p2p/peermanager.go @@ -39,7 +39,7 @@ const ( ) // PeerScore is a numeric score assigned to a peer (higher is better). -type PeerScore int +type PeerScore int16 const ( PeerScorePersistent PeerScore = math.MaxInt16 // persistent peers @@ -950,8 +950,16 @@ func (m *PeerManager) processPeerEvent(pu PeerUpdate) { switch pu.Status { case PeerStatusBad: + if m.store.peers[pu.NodeID].MutableScore == math.MinInt16 { + // TODO: should we inactivate the peer at this + // point? + return + } m.store.peers[pu.NodeID].MutableScore-- case PeerStatusGood: + if m.store.peers[pu.NodeID].MutableScore == math.MaxInt16 { + return + } m.store.peers[pu.NodeID].MutableScore++ } }