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);
|
||||
|
||||
// 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,
|
||||
'nonstandard',
|
||||
'too-long-mempool-chain',
|
||||
@ -1023,24 +1023,38 @@ Mempool.prototype.removeEntry = function removeEntry(entry, limit) {
|
||||
/**
|
||||
* Count the highest number of
|
||||
* ancestors a transaction may have.
|
||||
* @param {TX} tx
|
||||
* @param {MempoolEntry} entry
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Mempool.prototype.countAncestors = function countAncestors(entry, update) {
|
||||
return this._countAncestors(entry, 0, {}, true);
|
||||
Mempool.prototype.countAncestors = function countAncestors(entry) {
|
||||
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.
|
||||
* @private
|
||||
* @param {TX} tx
|
||||
* @param {MempoolEntry} entry
|
||||
* @param {Number} count
|
||||
* @param {Object} set
|
||||
* @param {MempoolEntry} child
|
||||
* @param {Boolean} update
|
||||
* @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 i, input, hash, pentry;
|
||||
|
||||
@ -1059,14 +1073,14 @@ Mempool.prototype._countAncestors = function countAncestors(entry, count, set, u
|
||||
count += 1;
|
||||
|
||||
if (update) {
|
||||
pentry.descFee += entry.fee;
|
||||
pentry.descSize += entry.size;
|
||||
pentry.descFee += child.fee;
|
||||
pentry.descSize += child.size;
|
||||
}
|
||||
|
||||
if (count > this.options.maxAncestors)
|
||||
break;
|
||||
|
||||
count = this._countAncestors(pentry, count, set);
|
||||
count = this._countAncestors(pentry, count, set, child, update);
|
||||
|
||||
if (count > this.options.maxAncestors)
|
||||
break;
|
||||
@ -1078,7 +1092,7 @@ Mempool.prototype._countAncestors = function countAncestors(entry, count, set, u
|
||||
/**
|
||||
* Count the highest number of
|
||||
* descendants a transaction may have.
|
||||
* @param {TX} tx
|
||||
* @param {MempoolEntry} entry
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
@ -1090,7 +1104,7 @@ Mempool.prototype.countDescendants = function countDescendants(entry) {
|
||||
* Count the highest number of
|
||||
* descendants a transaction may have.
|
||||
* @private
|
||||
* @param {TX} tx
|
||||
* @param {MempoolEntry} entry
|
||||
* @param {Number} count
|
||||
* @param {Object} set
|
||||
* @returns {Number}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user