diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 391e1b96..dacdcbe9 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -383,7 +383,10 @@ Chain.prototype.has = function has(hash, noProbe, cb) { return cb(true); } - return cb(!!this.orphan.map[hash]); + if (this.hasOrphan(hash)) + return cb(true); + + return cb(false); }; Chain.prototype.byHeight = function byHeight(height) { @@ -480,9 +483,13 @@ Chain.prototype.get = function get(hash, force, cb) { return; } } - assert(false); + // False positive: + // assert(false); } + if (!force && this.orphan.bmap[hash]) + return cb(this.orphan.bmap[hash]); + if (this.request.add(hash, cb)) this.emit('missing', hash, null, null); }; diff --git a/lib/bcoin/fullchain.js b/lib/bcoin/fullchain.js index dcd7ad52..c4c3a18f 100644 --- a/lib/bcoin/fullchain.js +++ b/lib/bcoin/fullchain.js @@ -249,8 +249,6 @@ Chain.prototype.add = function add(block) { }; Chain.prototype.has = function has(hash, noProbe, cb) { - var res; - if (typeof noProbe === 'function') { cb = noProbe; noProbe = false; @@ -263,13 +261,11 @@ Chain.prototype.has = function has(hash, noProbe, cb) { return; } - res = this.hasBlock(hash) || this.hasOrphan(hash); - - if (!cb) - return res; - cb = utils.asyncify(cb); - return cb(res); + + assert(!noProbe); + + return cb(this.hasBlock(hash) || this.hasOrphan(hash)); }; Chain.prototype.byHeight = function byHeight(height) { @@ -338,22 +334,14 @@ Chain.prototype.hashesInRange = function hashesInRange(start, end, cb) { }; Chain.prototype.getLast = function getLast(cb) { - var res; - if (this.loading) { this.once('load', function() { this.getLast(cb); }); return; } - - res = this.index.hashes[this.index.hashes.length - 1]; - - if (!cb) - return res; - cb = utils.asyncify(cb); - return cb(res); + return cb(this.index.hashes[this.index.hashes.length - 1]); }; Chain.prototype.getStartHeight = function getStartHeight() {