mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 15:07:24 +00:00
p2p: adjust max non-persistent peer score (#8137)
Guarantee persistent peers have the highest connecting priority. The peerStore.Ranked returns an arbitrary order of peers with the same scores.
This commit is contained in:
@@ -42,7 +42,8 @@ const (
|
||||
type PeerScore uint8
|
||||
|
||||
const (
|
||||
PeerScorePersistent PeerScore = math.MaxUint8 // persistent peers
|
||||
PeerScorePersistent PeerScore = math.MaxUint8 // persistent peers
|
||||
MaxPeerScoreNotPersistent PeerScore = PeerScorePersistent - 1
|
||||
)
|
||||
|
||||
// PeerUpdate is a peer update event sent via PeerUpdates.
|
||||
@@ -1283,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
|
||||
@@ -1294,10 +1298,6 @@ func (p *peerInfo) Score() PeerScore {
|
||||
return 0
|
||||
}
|
||||
|
||||
if score >= math.MaxUint8 {
|
||||
return PeerScore(math.MaxUint8)
|
||||
}
|
||||
|
||||
return PeerScore(score)
|
||||
}
|
||||
|
||||
|
||||
@@ -80,4 +80,20 @@ func TestPeerScoring(t *testing.T) {
|
||||
time.Millisecond,
|
||||
"startAt=%d score=%d", start, peerManager.Scores()[id])
|
||||
})
|
||||
t.Run("TestNonPersistantPeerUpperBound", func(t *testing.T) {
|
||||
start := int64(peerManager.Scores()[id] + 1)
|
||||
|
||||
for i := start; i <= int64(PeerScorePersistent); i++ {
|
||||
peerManager.processPeerEvent(ctx, PeerUpdate{
|
||||
NodeID: id,
|
||||
Status: PeerStatusGood,
|
||||
})
|
||||
|
||||
if i == int64(PeerScorePersistent) {
|
||||
require.EqualValues(t, MaxPeerScoreNotPersistent, peerManager.Scores()[id])
|
||||
} else {
|
||||
require.EqualValues(t, i, peerManager.Scores()[id])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user