diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index d66d8e39..c01c4794 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -601,6 +601,10 @@ Chain.prototype.getNextBlock = function getNextBlock(hash) { return this.index.hashes[entry.index + 1] || null; }; +Chain.prototype.size = function size() { + return this.index.hashes.length; +}; + Chain.prototype.toJSON = function toJSON() { var keep = 1000; diff --git a/lib/bcoin/fullchain.js b/lib/bcoin/fullchain.js index db1039ff..3c0b360e 100644 --- a/lib/bcoin/fullchain.js +++ b/lib/bcoin/fullchain.js @@ -431,6 +431,10 @@ Chain.prototype.getNextBlock = function getNextBlock(hash) { return entry.next.hash; }; +Chain.prototype.size = function size() { + return this.index.entries.length; +}; + Chain.prototype._save = function(entry) { var self = this; diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 8d88f0da..3724743a 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -330,8 +330,7 @@ Pool.prototype._handleMerkle = function _handleMerkle(block, peer) { Pool.prototype._handleBlock = function _handleBlock(block, peer) { var self = this; - var chainIndex = this.chain.index; - var hash, len, orphan, err; + var hash, size, orphan, err; if (this.listeners('watched').length > 0) { utils.nextTick(function() { @@ -347,7 +346,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) { this._response(block); hash = block.hash('hex'); - len = chainIndex.hashes.length; + size = this.chain.size(); orphan = this.chain.hasOrphan(block); err = this.chain.add(block); @@ -363,7 +362,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) { return; } - if (chainIndex.hashes.length === len) + if (this.chain.size() === size) return; this.emit('chain-progress', this.chain.fillPercent(), peer);