From 1dd0e366ac23429d206bb1d48302fa263713e5a1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 26 Feb 2017 22:04:17 -0800 Subject: [PATCH] mempool: fix descendant fees calculation. --- lib/mempool/mempool.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 8f708303..c157fd13 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -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}