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'
|
+ ' tip-chainwork=%s competitor-chainwork=%s'
|
||||||
+ ' chainwork-diff=%s (%s)',
|
+ ' chainwork-diff=%s (%s)',
|
||||||
entry.height,
|
entry.height,
|
||||||
utils.revHex(self.tip.hash),
|
|
||||||
utils.revHex(entry.hash),
|
|
||||||
self.tip.height,
|
self.tip.height,
|
||||||
entry.height,
|
entry.height,
|
||||||
|
utils.revHex(self.tip.hash),
|
||||||
|
utils.revHex(entry.hash),
|
||||||
self.tip.chainwork.toString(),
|
self.tip.chainwork.toString(),
|
||||||
entry.chainwork.toString(),
|
entry.chainwork.toString(),
|
||||||
self.tip.chainwork.sub(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) {
|
Fullnode.prototype.hasTX = function hasTX(hash, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.getTX(hash, function(err, tx) {
|
|
||||||
|
this.mempool.hasTX(hash, function(err, result) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(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) {
|
Mempool.prototype.countAncestorsSync = function countAncestorsSync(tx) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var inputs = new Array(tx.inputs.length);
|
var max = 0
|
||||||
var i, input, prev;
|
var i, input, prev, count;
|
||||||
|
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
prev = this.getTXSync(input.prevout.hash);
|
prev = this.getTXSync(input.prevout.hash);
|
||||||
inputs[i] = 0;
|
count = 0;
|
||||||
|
|
||||||
if (!prev)
|
if (!prev)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
inputs[i] += 1;
|
count += 1;
|
||||||
inputs[i] += this.countAncestorsSync(prev);
|
count += this.countAncestorsSync(prev);
|
||||||
|
|
||||||
|
if (count > max)
|
||||||
|
max = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return inputs.sort().pop();
|
return max;
|
||||||
};
|
};
|
||||||
|
|
||||||
Mempool.prototype.hasOrphanSync = function hasOrphanSync(hash) {
|
Mempool.prototype.hasOrphanSync = function hasOrphanSync(hash) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user