diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 4c12c3f7..4b2b33d1 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -1739,9 +1739,9 @@ Chain.prototype._getLocator = co(function* getLocator(start) { entry = this.tip; } + hash = entry.hash; height = entry.height; main = yield entry.isMainChain(); - hash = entry.hash; while (hash) { hashes.push(hash); @@ -1749,7 +1749,7 @@ Chain.prototype._getLocator = co(function* getLocator(start) { if (height === 0) break; - height = Math.max(height - step, 0); + height = Math.max(0, height - step); if (hashes.length > 10) step *= 2; diff --git a/lib/net/pool.js b/lib/net/pool.js index 1085f852..b6726c0b 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -162,7 +162,8 @@ Pool.prototype._init = function _init() { }); this.chain.on('reset', function() { - self.resetChain(); + if (self.checkpoints) + self.resetChain(); self.forceSync(); }); @@ -247,8 +248,7 @@ Pool.prototype.resetChain = function resetChain() { this.headerChain.push(new HeaderEntry(tip.hash, tip.height)); this.logger.info( 'Initialized header chain to height %d (checkpoint=%s).', - tip.height, - this.headerTip.hash); + tip.height, util.revHex(this.headerTip.hash)); } }; @@ -1143,7 +1143,8 @@ Pool.prototype.handleClose = co(function* handleClose(peer, connected) { if (loader) { this.logger.info('Removed loader peer (%s).', peer.hostname()); - this.resetChain(); + if (this.checkpoints) + this.resetChain(); } this.nonces.remove(peer.hostname());