From d6638c192ec9ab3aba303dab3df57e9b95a98b16 Mon Sep 17 00:00:00 2001 From: mononaut Date: Thu, 4 Jun 2026 07:56:40 +0000 Subject: [PATCH] don't retain cluster mempool parentMap longer than necessary --- .../src/cluster-mempool/cluster-mempool.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/backend/src/cluster-mempool/cluster-mempool.ts b/backend/src/cluster-mempool/cluster-mempool.ts index d3688b866..92e1bd5fa 100644 --- a/backend/src/cluster-mempool/cluster-mempool.ts +++ b/backend/src/cluster-mempool/cluster-mempool.ts @@ -42,7 +42,6 @@ const DEFAULT_COST_BUDGET = 75000; export class ClusterMempool { private clusters = new Map(); private txToCluster = new Map(); - private parentMap = new Map>(); private spentBy = new Map(); private mempool: Readonly<{ [txid: string]: MempoolTransactionExtended }>; private accelerations: { [txid: string]: { feeDelta: number } } = {}; @@ -147,15 +146,15 @@ export class ClusterMempool { } private buildFromMempool(): void { - this.buildRelativeMaps(); - const components = this.findMempoolComponents(); + const parentMap = this.buildRelativeMaps(); + const components = this.findMempoolComponents(parentMap); for (const component of components) { - this.createClusterFromTxids(component); + this.createClusterFromTxids(component, parentMap); } } - private buildRelativeMaps(): void { - this.parentMap.clear(); + private buildRelativeMaps(): Map> { + const parentMap = new Map>(); this.spentBy.clear(); for (const txid in this.mempool) { const tx = this.mempool[txid]; @@ -167,18 +166,19 @@ export class ClusterMempool { } } if (txParents.size > 0) { - this.parentMap.set(txid, txParents); + parentMap.set(txid, txParents); } } + return parentMap; } - private findMempoolComponents(): Set[] { + private findMempoolComponents(parentMap: Map>): Set[] { const visited = new Set(); const components: Set[] = []; for (const txid in this.mempool) { if (!visited.has(txid)) { - const component = this.dfsComponent(txid, visited); + const component = this.dfsComponent(txid, visited, parentMap); components.push(component); } } @@ -187,7 +187,8 @@ export class ClusterMempool { private dfsComponent( startTxid: string, - visited: Set + visited: Set, + parentMap: Map> ): Set { const component = new Set(); const stack = [startTxid]; @@ -197,7 +198,7 @@ export class ClusterMempool { visited.add(current); component.add(current); - const txParents = this.parentMap.get(current); + const txParents = parentMap.get(current); if (txParents) { for (const p of txParents) { if (!visited.has(p)) { @@ -229,7 +230,8 @@ export class ClusterMempool { } private createClusterFromTxids( - txids: Set + txids: Set, + parentMap: Map> ): Cluster | null { const clusterId = this.nextClusterId++; const depgraph = new DepGraph(); @@ -246,7 +248,7 @@ export class ClusterMempool { } for (const txid of txids) { - const txParents = this.parentMap.get(txid); + const txParents = parentMap.get(txid); if (txParents) { for (const parentTxid of txParents) { if (txids.has(parentTxid)) {