Skip to content

Commit bfb36e5

Browse files
committed
netsync: process inv announcements when no syncPeer is set
handleInvMsg early-returned for any inv from a non-syncPeer whenever sm.current() was false, with the comment that it prevents fetching a mass of orphans. That guard assumes a syncPeer is already fetching blocks; when syncPeer is nil, the assumption breaks down and the early return becomes a deadlock. The deadlock is reachable whenever two nodes connect at equal heights: startSync exits without picking a syncPeer (no peer is "higher"), and nothing later promotes the freshly-mined blocks the peer announces via inv. The pre-verack disconnect and sync-race regression tests in integration/sync_race_test.go fail consistently because of this. Only skip the inv when we actually have a syncPeer. When syncPeer is nil, fall through and let the normal request path queue the block -- the inv is the only signal that there are blocks to fetch.
1 parent 79752a8 commit bfb36e5

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

netsync/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,10 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) {
11241124
peer.UpdateLastAnnouncedBlock(&invVects[lastBlock].Hash)
11251125
}
11261126

1127-
// Ignore invs from peers that aren't the sync if we are not current.
1128-
// Helps prevent fetching a mass of orphans.
1129-
if peer != sm.syncPeer && !sm.current() {
1127+
// Ignore invs from peers that aren't the sync peer if we are not
1128+
// current. Helps prevent fetching a mass of orphans. When syncPeer
1129+
// is nil, accept invs from any peer.
1130+
if sm.syncPeer != nil && peer != sm.syncPeer && !sm.current() {
11301131
return
11311132
}
11321133

0 commit comments

Comments
 (0)