From e54e896e569e09b6070e24792e5b1aa198fc8d43 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sat, 3 Dec 2022 12:10:54 +0900 Subject: [PATCH] fix skipped descendant updates on tx inclusion --- backend/src/api/tx-selection-worker.ts | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/backend/src/api/tx-selection-worker.ts b/backend/src/api/tx-selection-worker.ts index 206d26fe3..ca40af84f 100644 --- a/backend/src/api/tx-selection-worker.ts +++ b/backend/src/api/tx-selection-worker.ts @@ -106,44 +106,44 @@ function makeBlockTemplates({ mempool, blockLimit, weightLimit, condenseRest }: if (nextTx && !nextTx?.used) { // Check if the package fits into this block if (blockWeight + nextTx.ancestorWeight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) { - blockWeight += nextTx.ancestorWeight; const ancestors: AuditTransaction[] = Array.from(nextTx.ancestorMap.values()); const descendants: AuditTransaction[] = []; // sort ancestors by dependency graph (equivalent to sorting by ascending ancestor count) const sortedTxSet = [...ancestors.sort((a, b) => { return (a.ancestorMap.size || 0) - (b.ancestorMap.size || 0); }), nextTx]; const effectiveFeeRate = nextTx.ancestorFee / (nextTx.ancestorWeight / 4); - + const used: AuditTransaction[] = []; while (sortedTxSet.length) { const ancestor = sortedTxSet.pop(); const mempoolTx = mempool[ancestor.txid]; - if (ancestor && !ancestor?.used) { - ancestor.used = true; - // update original copy of this tx with effective fee rate & relatives data - mempoolTx.effectiveFeePerVsize = effectiveFeeRate; - mempoolTx.ancestors = sortedTxSet.map((a) => { - return { - txid: a.txid, - fee: a.fee, - weight: a.weight, - }; - }).reverse(); - mempoolTx.descendants = descendants.map((a) => { - return { - txid: a.txid, - fee: a.fee, - weight: a.weight, - }; - }); - descendants.push(ancestor); - mempoolTx.cpfpChecked = true; - transactions.push(ancestor); - blockSize += ancestor.size; - } + ancestor.used = true; + ancestor.usedBy = nextTx.txid; + // update original copy of this tx with effective fee rate & relatives data + mempoolTx.effectiveFeePerVsize = effectiveFeeRate; + mempoolTx.ancestors = sortedTxSet.map((a) => { + return { + txid: a.txid, + fee: a.fee, + weight: a.weight, + }; + }).reverse(); + mempoolTx.descendants = descendants.map((a) => { + return { + txid: a.txid, + fee: a.fee, + weight: a.weight, + }; + }); + descendants.push(ancestor); + mempoolTx.cpfpChecked = true; + transactions.push(ancestor); + blockSize += ancestor.size; + blockWeight += ancestor.weight; + used.push(ancestor); } // remove these as valid package ancestors for any descendants remaining in the mempool - if (sortedTxSet.length) { - sortedTxSet.forEach(tx => { + if (used.length) { + used.forEach(tx => { updateDescendants(tx, auditPool, modified); }); }