[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
This commit is contained in:
Ori Newman 2020-04-01 12:56:10 +03:00 committed by GitHub
parent 36d866375e
commit b20a7a679b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {