fix countAncestors and fix fork warning.
This commit is contained in:
parent
4d30c9428a
commit
03589f1df1
@ -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(),
|
||||
|
||||
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user