From d1f8e9b5ffce9d215faaa31e1e68d8e2d56f2c44 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 18 Dec 2015 16:57:37 -0800 Subject: [PATCH] add chain.hasOrphan method. --- lib/bcoin/chain.js | 15 ++++++++++++++- lib/bcoin/peer.js | 3 +-- 2 files changed, 15 insertions(+), 3 deletions(-) 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; }