mempool: fix descendant fees calculation.
This commit is contained in:
parent
6d4a2c61cb
commit
1dd0e366ac
@ -860,7 +860,7 @@ Mempool.prototype.verify = co(function* verify(entry, view) {
|
|||||||
throw new VerifyError(tx, 'highfee', 'absurdly-high-fee', 0);
|
throw new VerifyError(tx, 'highfee', 'absurdly-high-fee', 0);
|
||||||
|
|
||||||
// Why do we have this here? Nested transactions are cool.
|
// Why do we have this here? Nested transactions are cool.
|
||||||
if (this.countAncestors(entry, true) > this.options.maxAncestors) {
|
if (this.updateAncestors(entry) > this.options.maxAncestors) {
|
||||||
throw new VerifyError(tx,
|
throw new VerifyError(tx,
|
||||||
'nonstandard',
|
'nonstandard',
|
||||||
'too-long-mempool-chain',
|
'too-long-mempool-chain',
|
||||||
@ -1023,24 +1023,38 @@ Mempool.prototype.removeEntry = function removeEntry(entry, limit) {
|
|||||||
/**
|
/**
|
||||||
* Count the highest number of
|
* Count the highest number of
|
||||||
* ancestors a transaction may have.
|
* ancestors a transaction may have.
|
||||||
* @param {TX} tx
|
* @param {MempoolEntry} entry
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Mempool.prototype.countAncestors = function countAncestors(entry, update) {
|
Mempool.prototype.countAncestors = function countAncestors(entry) {
|
||||||
return this._countAncestors(entry, 0, {}, true);
|
return this._countAncestors(entry, 0, {}, entry, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count the highest number of
|
||||||
|
* ancestors a transaction may have.
|
||||||
|
* Update descendant fees and size.
|
||||||
|
* @param {MempoolEntry} entry
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Mempool.prototype.updateAncestors = function updateAncestors(entry) {
|
||||||
|
return this._countAncestors(entry, 0, {}, entry, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Traverse ancestors and count.
|
* Traverse ancestors and count.
|
||||||
* @private
|
* @private
|
||||||
* @param {TX} tx
|
* @param {MempoolEntry} entry
|
||||||
* @param {Number} count
|
* @param {Number} count
|
||||||
* @param {Object} set
|
* @param {Object} set
|
||||||
|
* @param {MempoolEntry} child
|
||||||
|
* @param {Boolean} update
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Mempool.prototype._countAncestors = function countAncestors(entry, count, set, update) {
|
Mempool.prototype._countAncestors = function countAncestors(entry, count, set, child, update) {
|
||||||
var tx = entry.tx;
|
var tx = entry.tx;
|
||||||
var i, input, hash, pentry;
|
var i, input, hash, pentry;
|
||||||
|
|
||||||
@ -1059,14 +1073,14 @@ Mempool.prototype._countAncestors = function countAncestors(entry, count, set, u
|
|||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
pentry.descFee += entry.fee;
|
pentry.descFee += child.fee;
|
||||||
pentry.descSize += entry.size;
|
pentry.descSize += child.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > this.options.maxAncestors)
|
if (count > this.options.maxAncestors)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
count = this._countAncestors(pentry, count, set);
|
count = this._countAncestors(pentry, count, set, child, update);
|
||||||
|
|
||||||
if (count > this.options.maxAncestors)
|
if (count > this.options.maxAncestors)
|
||||||
break;
|
break;
|
||||||
@ -1078,7 +1092,7 @@ Mempool.prototype._countAncestors = function countAncestors(entry, count, set, u
|
|||||||
/**
|
/**
|
||||||
* Count the highest number of
|
* Count the highest number of
|
||||||
* descendants a transaction may have.
|
* descendants a transaction may have.
|
||||||
* @param {TX} tx
|
* @param {MempoolEntry} entry
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1090,7 +1104,7 @@ Mempool.prototype.countDescendants = function countDescendants(entry) {
|
|||||||
* Count the highest number of
|
* Count the highest number of
|
||||||
* descendants a transaction may have.
|
* descendants a transaction may have.
|
||||||
* @private
|
* @private
|
||||||
* @param {TX} tx
|
* @param {MempoolEntry} entry
|
||||||
* @param {Number} count
|
* @param {Number} count
|
||||||
* @param {Object} set
|
* @param {Object} set
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user