From b10bd05207c82001621edb07f9d068a9f5d5c11a Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sat, 6 Jan 2024 22:41:03 +0000 Subject: [PATCH] Move max cpfp graph size to named const --- backend/src/api/cpfp.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/src/api/cpfp.ts b/backend/src/api/cpfp.ts index cf54771bb..aefdad5a0 100644 --- a/backend/src/api/cpfp.ts +++ b/backend/src/api/cpfp.ts @@ -1,6 +1,7 @@ import { CpfpInfo, MempoolTransactionExtended } from '../mempool.interfaces'; const CPFP_UPDATE_INTERVAL = 60_000; // update CPFP info at most once per 60s per transaction +const MAX_GRAPH_SIZE = 50; // the maximum number of in-mempool relatives to consider interface GraphTx extends MempoolTransactionExtended { depends: string[]; @@ -92,13 +93,13 @@ function mempoolToGraphTx(tx: MempoolTransactionExtended): GraphTx { } /** - * Takes a map of transaction ancestors, and expands it into a full graph of up to 50 in-mempool relatives + * Takes a map of transaction ancestors, and expands it into a full graph of up to MAX_GRAPH_SIZE in-mempool relatives */ function expandRelativesGraph(mempool: { [txid: string]: MempoolTransactionExtended }, ancestors: Map): Map { const relatives: Map = new Map(); const stack: GraphTx[] = Array.from(ancestors.values()); while (stack.length > 0) { - if (relatives.size > 50) { + if (relatives.size > MAX_GRAPH_SIZE) { return relatives; } @@ -170,7 +171,7 @@ function calculateCpfpCluster(txid: string, graph: Map): Map(best?.ancestorMap?.entries() || []); while (sortedRelatives.length && best && (best.txid !== tx.txid && !best.ancestorMap.has(tx.txid)) && maxIterations > 0) { @@ -236,7 +237,7 @@ function calculateCpfpCluster(txid: string, graph: Map): Map, visited: Map>, depth: number = 0): Map { // sanity check for infinite recursion / too many ancestors (should never happen) - if (depth > 50) { + if (depth > MAX_GRAPH_SIZE) { return tx.ancestorMap; }