Skip to content

Commit

Permalink
fix score type
Browse files Browse the repository at this point in the history
  • Loading branch information
blindchaser committed Oct 28, 2024
1 parent 10b32a5 commit e007e86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/p2p/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func (m *PeerManager) newPeerInfo(id types.NodeID) peerInfo {
peerInfo := peerInfo{
ID: id,
AddressInfo: map[NodeAddress]*peerAddressInfo{},
MutableScore: int64(DefaultMutableScore), // Should start with a default value above 0
MutableScore: DefaultMutableScore, // Should start with a default value above 0
}
return m.configurePeer(peerInfo)
}
Expand Down Expand Up @@ -1350,7 +1350,7 @@ type peerInfo struct {
Height int64
FixedScore PeerScore // mainly for tests

MutableScore int64 // updated by router
MutableScore PeerScore // updated by router

ConsecSuccessfulBlocks int64
}
Expand Down Expand Up @@ -1418,7 +1418,7 @@ func (p *peerInfo) Score() PeerScore {
return PeerScoreUnconditional
}

score := p.MutableScore
score := int64(p.MutableScore)
if p.Persistent || p.BlockSync {
score = int64(PeerScorePersistent)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/p2p/peermanager_scoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package p2p

import (
"context"
"github.com/tendermint/tendermint/libs/log"
"strings"
"testing"
"time"

"github.com/tendermint/tendermint/libs/log"

"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"

Expand Down Expand Up @@ -44,15 +45,15 @@ func TestPeerScoring(t *testing.T) {
NodeID: id,
Status: PeerStatusGood,
})
require.EqualValues(t, defaultScore+int64(i), peerManager.Scores()[id])
require.EqualValues(t, defaultScore+PeerScore(i), peerManager.Scores()[id])
}
// watch the corresponding decreases respond to update
for i := 1; i < 10; i++ {
peerManager.processPeerEvent(ctx, PeerUpdate{
NodeID: id,
Status: PeerStatusBad,
})
require.EqualValues(t, DefaultMutableScore+int64(9)-int64(i), peerManager.Scores()[id])
require.EqualValues(t, DefaultMutableScore+PeerScore(9)-PeerScore(i), peerManager.Scores()[id])
}

// Dial failure should decrease score
Expand Down

0 comments on commit e007e86

Please sign in to comment.