-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use peermanager scores for blocksync peers and don't error out on block mismatch #162
Changes from 2 commits
5786063
1ac69bc
fe9f6e0
08f8163
2f4517f
bfc637c
533f759
8fa8638
1137ac4
2bc2fbb
3610170
a1bd259
a83139b
ae4b8bc
e398b04
3f06493
a70ffd2
e47270c
36d31f9
ecf6e7f
a149386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/tendermint/tendermint/internal/p2p" | ||
"math" | ||
"sort" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
@@ -80,6 +82,7 @@ type BlockPool struct { | |
height int64 // the lowest key in requesters. | ||
// peers | ||
peers map[types.NodeID]*bpPeer | ||
peerManager *p2p.PeerManager | ||
maxPeerHeight int64 // the biggest reported height | ||
|
||
// atomic | ||
|
@@ -101,8 +104,8 @@ func NewBlockPool( | |
start int64, | ||
requestsCh chan<- BlockRequest, | ||
errorsCh chan<- peerError, | ||
peerManager *p2p.PeerManager, | ||
) *BlockPool { | ||
|
||
bp := &BlockPool{ | ||
logger: logger, | ||
peers: make(map[types.NodeID]*bpPeer), | ||
|
@@ -113,6 +116,7 @@ func NewBlockPool( | |
requestsCh: requestsCh, | ||
errorsCh: errorsCh, | ||
lastSyncRate: 0, | ||
peerManager: peerManager, | ||
} | ||
bp.BaseService = *service.NewBaseService(logger, "BlockPool", bp) | ||
return bp | ||
|
@@ -408,13 +412,31 @@ func (pool *BlockPool) updateMaxPeerHeight() { | |
pool.maxPeerHeight = max | ||
} | ||
|
||
func (pool *BlockPool) getSortedPeers(peers map[types.NodeID]*bpPeer) []types.NodeID { | ||
// Generate a sorted list | ||
sortedPeers := make([]types.NodeID, 0, len(peers)) | ||
|
||
for peer := range peers { | ||
sortedPeers = append(sortedPeers, peer) | ||
} | ||
sort.Slice(sortedPeers, func(i, j int) bool { | ||
return pool.peerManager.Score(sortedPeers[i]) > pool.peerManager.Score(sortedPeers[j]) | ||
}) | ||
return sortedPeers | ||
} | ||
|
||
// Pick an available peer with the given height available. | ||
// If no peers are available, returns nil. | ||
func (pool *BlockPool) pickIncrAvailablePeer(height int64) *bpPeer { | ||
pool.mtx.Lock() | ||
defer pool.mtx.Unlock() | ||
|
||
for _, peer := range pool.peers { | ||
// Generate a sorted list | ||
sortedPeers := pool.getSortedPeers(pool.peers) | ||
fmt.Printf("PSUDEBUG - block sync with sorted peers: %v\n", sortedPeers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we remove this debug log? |
||
for _, nodeId := range sortedPeers { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few further optimizations we can do:
|
||
peer := pool.peers[nodeId] | ||
pool.peerManager.Score(peer.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we get the score out here without using it? |
||
if peer.didTimeout { | ||
pool.removePeer(peer.id) | ||
continue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: fix lint issue