From f488a02d2d5f5554a19624a569a8153a0e199e2c Mon Sep 17 00:00:00 2001 From: Sky Young Date: Mon, 27 Aug 2018 12:10:02 -0700 Subject: [PATCH] Fix syncComplete calculations The _lastHeaderCount would always be 2000 behind upon startup, even if it is synced with the last header, causing no more headers to be synced. This fixes the issue that prevented syncing occasionally after restart. --- lib/services/header/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/services/header/index.js b/lib/services/header/index.js index 86cb2b3f..4251489b 100644 --- a/lib/services/header/index.js +++ b/lib/services/header/index.js @@ -573,12 +573,15 @@ HeaderService.prototype._startBlockSubscription = function() { }; HeaderService.prototype._syncComplete = function() { + // Check if we have reached the last block that we can download. + var bestHeight = Math.max(this._bestHeight, this._lastHeader.height); - // we always ask for the max number of headers, which is 2000. - // so any response with < 2000 means we have reached the end of the headers list. - // we could make an extra call if the number of total headers is multiple of 2000. - return this._lastHeaderCount < 2000; + var syncComplete = bestHeight === this._tip.height + if (syncComplete) + log.info("Header Service: Sync Complete!") + + return syncComplete }; HeaderService.prototype._setBestHeader = function() {