Browse Source

move the score cap check to a better place

pull/8137/head
jay tseng 3 years ago
parent
commit
9ffee8f1ce
No known key found for this signature in database GPG Key ID: 5A9D3063305E6427
1 changed files with 4 additions and 9 deletions
  1. +4
    -9
      internal/p2p/peermanager.go

+ 4
- 9
internal/p2p/peermanager.go View File

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


Loading…
Cancel
Save