diff --git a/lib/net/pool.js b/lib/net/pool.js index bad46a04..b6fda0a4 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -197,6 +197,7 @@ Pool.prototype._init = function _init() { }); this.chain.on('reset', function() { + self.resetChain(); self.forceSync(); }); @@ -263,7 +264,7 @@ Pool.prototype.resetChain = function resetChain() { if (!this.options.headers) return; - if (!this.options.useCheckpoints) + if (!this.chain.options.useCheckpoints) return; this.headersFirst = false; @@ -897,30 +898,7 @@ Pool.prototype._handleBlock = co(function* handleBlock(peer, block) { throw err; } - if (this.logger.level >= 4 && this.chain.total % 20 === 0) { - this.logger.debug('Status:' - + ' ts=%s height=%d progress=%s' - + ' blocks=%d orphans=%d active=%d' - + ' target=%s peers=%d' - + ' pending=%d jobs=%d', - util.date(block.ts), - this.chain.height, - (this.chain.getProgress() * 100).toFixed(2) + '%', - this.chain.total, - this.chain.orphanCount, - this.requestMap.size, - block.bits, - this.peers.size(), - this.locker.pending, - this.locker.jobs.length); - } - - if (this.chain.total % 2000 === 0) { - this.logger.info( - 'Received 2000 more blocks (height=%d, hash=%s).', - this.chain.height, - block.rhash()); - } + this.logStatus(block); if (!this.headersFirst) return; @@ -947,6 +925,39 @@ Pool.prototype._handleBlock = co(function* handleBlock(peer, block) { peer.sendGetBlocks([hash], null); }); +/** + * Log sync status. + * @private + * @param {Block} block + */ + +Pool.prototype.logStatus = function logStatus(block) { + if (this.logger.level >= 4 && this.chain.total % 20 === 0) { + this.logger.debug('Status:' + + ' ts=%s height=%d progress=%s' + + ' blocks=%d orphans=%d active=%d' + + ' target=%s peers=%d' + + ' pending=%d jobs=%d', + util.date(block.ts), + this.chain.height, + (this.chain.getProgress() * 100).toFixed(2) + '%', + this.chain.total, + this.chain.orphanCount, + this.requestMap.size, + block.bits, + this.peers.size(), + this.locker.pending, + this.locker.jobs.length); + } + + if (this.chain.total % 2000 === 0) { + this.logger.info( + 'Received 2000 more blocks (height=%d, hash=%s).', + this.chain.height, + block.rhash()); + } +}; + /** * Handle a transaction. Attempt to add to mempool. * @private @@ -2114,7 +2125,6 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) { if (this.spv) { this.requiredServices |= common.services.BLOOM; this.services &= ~common.services.NETWORK; - this.useCheckpoints = true; this.noRelay = true; }