Skip to content

Commit

Permalink
netsync: don't add peer if we're not current and the peer is not a sync
Browse files Browse the repository at this point in the history
candidate

Since we can use all the peers we could get for ibd, don't add peers
that are not sync candidates when we're still not current.
  • Loading branch information
kcalvinalvin committed Dec 9, 2024
1 parent 6bae737 commit d5b78aa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,17 @@ func (sm *SyncManager) handleNewPeerMsg(peer *peerpkg.Peer) {
return
}

log.Infof("New valid peer %s (%s)", peer, peer.UserAgent())

// Initialize the peer state.
isSyncCandidate := sm.isSyncCandidate(peer)
if !sm.current() && !isSyncCandidate {
log.Infof("New peer %s (%s) is not a valid sync candidate -- disconnecting",
peer, peer.UserAgent())
peer.Disconnect()
return
}

log.Infof("New valid peer %s (%s)", peer, peer.UserAgent())

sm.peerStates[peer] = &peerSyncState{
syncCandidate: isSyncCandidate,
requestedTxns: make(map[chainhash.Hash]struct{}),
Expand Down

0 comments on commit d5b78aa

Please sign in to comment.