diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 8f713cca..b215bd31 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -381,13 +381,26 @@ Chain.prototype.has = function has(hash, noProbe, cb) { return cb(!!this.orphan.map[hash]); }; -Chain.prototype.hasBlock = function hasBlock(hash, noProbe, strict) { +Chain.prototype.hasBlock = function hasBlock(hash) { if (this.loading) return false; + if (Array.isArray(hash)) + hash = utils.toHex(hash); + return this.index.bloom.test(hash, 'hex'); }; +Chain.prototype.hasOrphan = function hasOrphan(hash) { + if (this.loading) + return false; + + if (Array.isArray(hash)) + hash = utils.toHex(hash); + + return !!this.orphan.bmap[hash]; +}; + Chain.prototype.get = function get(hash, force, cb) { if (typeof force === 'function') { cb = force; diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index b4d17d26..ed65bff1 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -460,12 +460,11 @@ Peer.prototype._handleInv = function handleInv(items) { for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; var hash = utils.toHex(block); - if (this.chain.orphan.bmap[hash]) { + if (this.chain.hasOrphan(hash)) { this.loadBlocks(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash)); continue; } if (!this.chain.hasBlock(hash)) { - // this.getData({ type: 'block', hash: hash }); req.push({ type: 'block', hash: block }); continue; }