From 39afa4cda13979f81f58248a324bddcfd9811548 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 18 Oct 2022 21:03:21 +0000 Subject: [PATCH] Fix errors in block audit tx selection algorithm --- backend/src/api/mempool-blocks.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/src/api/mempool-blocks.ts b/backend/src/api/mempool-blocks.ts index 9b58f4754..2fb524b11 100644 --- a/backend/src/api/mempool-blocks.ts +++ b/backend/src/api/mempool-blocks.ts @@ -207,10 +207,10 @@ class MempoolBlocks { if (nextTxSet && blockWeight + nextTxSet.weight < config.MEMPOOL.BLOCK_WEIGHT_UNITS) { blockWeight += nextTxSet.weight; // sort txSet by dependency graph (equivalent to sorting by ascending ancestor count) - const sortedTxSet = nextTx.ancestors.sort((a, b) => { + const sortedTxSet = [...nextTx.ancestors.sort((a, b) => { return (mempool[a.txid]?.ancestors?.length || 0) - (mempool[b.txid]?.ancestors?.length || 0); - }); - [...sortedTxSet, nextTx].forEach((ancestor, i, arr) => { + }), nextTx]; + sortedTxSet.forEach((ancestor, i, arr) => { const tx = mempool[ancestor.txid]; const txSet = txSets[ancestor.txid]; if (txSet.available) { @@ -340,7 +340,7 @@ class MempoolBlocks { if (txSet.children) { txSet.children.forEach(childId => { const child = mempool[childId]; - if (child && child.ancestors && txSets[childId]?.available) { + if (child && child.ancestors) { const ancestorIndex = child.ancestors.findIndex(a => a.txid === root.txid); if (ancestorIndex > -1) { // remove tx as ancestor @@ -355,11 +355,12 @@ class MempoolBlocks { childTxSet.modified = true; modified.push(child); } - - // recursively update grandchildren - anyModified = this.updateDescendants(root, child, mempool, txSets, modified) || anyModified; } } + // recursively update grandchildren + if (child) { + anyModified = this.updateDescendants(root, child, mempool, txSets, modified) || anyModified; + } }); } return anyModified;