diff --git a/netsync/manager.go b/netsync/manager.go index e267c9bff..bc1cefb20 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -650,6 +650,8 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) { } } + haveUnknownInvBlock := false + // Request the advertised inventory if we don't already have it. Also, // request parent blocks of orphans if we receive one we already have. // Finally, attempt to detect potential stalls due to big orphan DAGs @@ -689,6 +691,10 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) { } } + if iv.Type == wire.InvTypeBlock { + haveUnknownInvBlock = true + } + // Add it to the request queue. state.addInvToRequestQueue(iv) continue @@ -733,6 +739,13 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) { if err != nil { log.Errorf("Failed to send invs from queue: %s", err) } + + if haveUnknownInvBlock && !sm.current() { + // If one of the inv messages is an unknown block + // it is an indication that one of our peers has more + // up-to-date data than us. + sm.restartSyncIfNeeded() + } } func (sm *SyncManager) addInvsToGetDataMessageFromQueue(gdmsg *wire.MsgGetData, state *peerSyncState, invType wire.InvType, maxInvsToAdd int) error {