From b20a7a679b8b78af6bb7d280b7ba9d5d47f4ecf0 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Wed, 1 Apr 2020 12:56:10 +0300 Subject: [PATCH] [NOD-874] If the node is not current call sm.restartSyncIfNeeded() on handleInvMsg (#684) * [NOD-874] If the node is not current call sm.restartSyncIfNeeded() on handleInvMsg * [NOD-874] Check haveUnknownInvBlock before restartSyncIfNeeded * [NOD-874] Fix comment * [NOD-874] Fix comment * [NOD-874] Fix comment --- netsync/manager.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 {