Skip to content

Commit

Permalink
netsync: fix bug in peer selection logic
Browse files Browse the repository at this point in the history
On fetchHeaderBlocks and fetchUtreexoHeaders, we make sure that both the
syncPeer and the passed in peer are not nil. We also only prefer the
passed in peer if it is not nil.
  • Loading branch information
kcalvinalvin committed Jan 21, 2025
1 parent 2d4bb72 commit 5939535
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,15 @@ func (sm *SyncManager) fetchUtreexoHeaders(peer *peerpkg.Peer) {
return
}

// Can't fetch if both are nil.
if peer == nil && sm.syncPeer == nil {
log.Warnf("fetchUtreexoHeader called with syncPeer and peer as nil")
return
}

// Default to the syncPeer unless we're given a peer by the caller.
reqPeer := sm.syncPeer
if reqPeer == nil {
if peer != nil {
reqPeer = peer
}

Expand Down Expand Up @@ -1134,9 +1140,15 @@ func (sm *SyncManager) fetchHeaderBlocks(peer *peerpkg.Peer) {
return
}

// Can't fetch if both are nil.
if peer == nil && sm.syncPeer == nil {
log.Warnf("fetchHeaderBlocks called with syncPeer and peer as nil")
return
}

// Default to the syncPeer unless we're given a peer by the caller.
reqPeer := sm.syncPeer
if reqPeer == nil {
if peer != nil {
reqPeer = peer
}

Expand Down

0 comments on commit 5939535

Please sign in to comment.