From 5b1ee4cccbdf96e8916f98689ccae2e95850b7f0 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 29 Feb 2016 01:53:08 -0800 Subject: [PATCH] ignore orphan soil for request map. fix block delta. --- lib/bcoin/block.js | 2 ++ lib/bcoin/chain.js | 11 +++++++---- lib/bcoin/pool.js | 18 +++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 8b2f316b..f260631c 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -64,6 +64,8 @@ Block.prototype.renderWitness = function renderWitness() { }; Block.prototype.getRaw = function getRaw() { + var raw; + if (this._raw) { assert(this._size > 0); assert(this._witnessSize >= 0); diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index f2012766..c1780336 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -48,7 +48,6 @@ function Chain(options) { this.invalid = {}; this.bestHeight = -1; this.lastUpdate = utils.now(); - this.blockDelta = 0; this.orphan = { map: {}, @@ -795,7 +794,6 @@ Chain.prototype._addEntry = function _addEntry(entry, block, callback) { return callback(null, false); now = utils.now(); - this.blockDelta = now - this.lastUpdate; this.lastUpdate = now; this._saveBlock(block, function(err) { @@ -1621,15 +1619,20 @@ Chain.prototype.isFull = function isFull() { delta = utils.now() - this.tip.ts; - return delta < 40 * 60; + return delta < 4 * 60 * 60; }; Chain.prototype.isInitial = function isInitial() { + var now, delta; + if (!this.tip) return true; + now = utils.now(); + delta = now - this.lastUpdate; + // Should mimic the original IsInitialBlockDownload() function - return this.blockDelta < 10 && this.tip.ts < utils.now() - 24 * 60 * 60; + return delta < 10 && this.tip.ts < now - 24 * 60 * 60; }; Chain.prototype.getProgress = function getProgress() { diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 47f7edb7..a87f4a56 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -74,7 +74,7 @@ function Pool(options) { interval: options.loadInterval || 20000 }; - this.requestTimeout = options.requestTimeout || 600000; + this.requestTimeout = options.requestTimeout || 2 * 60000; this.chain = new bcoin.chain({ spv: options.spv, @@ -271,10 +271,10 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan) { // If we're already processing the block // that would resolve this, ignore. - if (self.request.map[orphan.soil]) { - utils.debug('Already requested orphan "soil".'); - return; - } + // if (self.request.map[orphan.soil]) { + // utils.debug('Already requested orphan "soil".'); + // return; + // } if (self.chain.hasPending(orphan.soil)) { utils.debug('Already processing orphan "soil".'); @@ -441,6 +441,7 @@ Pool.prototype._addLoader = function _addLoader() { peer.on('merkleblock', function(block) { if (!self.options.spv) return; + if (!self.syncing) return; @@ -460,6 +461,7 @@ Pool.prototype._addLoader = function _addLoader() { peer.on('block', function(block) { if (self.options.spv) return; + if (!self.syncing) return; @@ -708,8 +710,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) { if (self.chain.height % 20 === 0) { utils.debug( 'Status: tip=%s ts=%s height=%d blocks=%d orphans=%d active=%d' - + ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d' - + ' blockdelta=%d', + + ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d', block.rhash, new Date(block.ts * 1000).toISOString().slice(0, -5) + 'Z', self.chain.height, @@ -721,8 +722,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) { self.peers.all.length, self.chain.pending.length, self.chain.bestHeight, - self.chain.jobs.length, - self.chain.blockDelta); + self.chain.jobs.length); } return callback(null, true);