diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index f0d0e746..d0a58a6b 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -92,10 +92,10 @@ Chain.prototype._init = function _init() { + ' tip-chainwork=%s competitor-chainwork=%s' + ' chainwork-diff=%s (%s)', entry.height, - utils.revHex(self.tip.hash), - utils.revHex(entry.hash), self.tip.height, entry.height, + utils.revHex(self.tip.hash), + utils.revHex(entry.hash), self.tip.chainwork.toString(), entry.chainwork.toString(), self.tip.chainwork.sub(entry.chainwork).toString(), diff --git a/lib/bcoin/fullnode.js b/lib/bcoin/fullnode.js index 5613f7d8..2286124e 100644 --- a/lib/bcoin/fullnode.js +++ b/lib/bcoin/fullnode.js @@ -331,10 +331,15 @@ Fullnode.prototype.getTX = function getTX(hash, callback) { Fullnode.prototype.hasTX = function hasTX(hash, callback) { var self = this; - return this.getTX(hash, function(err, tx) { + + this.mempool.hasTX(hash, function(err, result) { if (err) return callback(err); - return callback(null, !!tx); + + if (result) + return callback(null, true); + + self.chain.db.hasTX(hash, callback); }); }; diff --git a/lib/bcoin/mempool.js b/lib/bcoin/mempool.js index 44de457f..38ad109c 100644 --- a/lib/bcoin/mempool.js +++ b/lib/bcoin/mempool.js @@ -849,22 +849,25 @@ Mempool.prototype.verify = function verify(tx, callback) { Mempool.prototype.countAncestorsSync = function countAncestorsSync(tx) { var self = this; - var inputs = new Array(tx.inputs.length); - var i, input, prev; + var max = 0 + var i, input, prev, count; for (i = 0; i < tx.inputs.length; i++) { input = tx.inputs[i]; prev = this.getTXSync(input.prevout.hash); - inputs[i] = 0; + count = 0; if (!prev) continue; - inputs[i] += 1; - inputs[i] += this.countAncestorsSync(prev); + count += 1; + count += this.countAncestorsSync(prev); + + if (count > max) + max = count; } - return inputs.sort().pop(); + return max; }; Mempool.prototype.hasOrphanSync = function hasOrphanSync(hash) {