From 97b32b97edea28b72f9be3dd82c468f57f401926 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 27 Jun 2026 17:38:03 -0700 Subject: Skip the mempool backlog on startup for large (mainnet) mempools First mempool pass over a >200-tx mempool would fire thousands of getrawtransaction calls at the node in a burst. Mark the existing backlog seen and scan only new arrivals instead; small (regtest) mempools still scan fully. Co-Authored-By: Claude Opus 4.8 (1M context) --- tools/sp-indexer.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/sp-indexer.js b/tools/sp-indexer.js index 934c55c..5611bb5 100644 --- a/tools/sp-indexer.js +++ b/tools/sp-indexer.js @@ -169,10 +169,18 @@ async function scanMempoolTx(txid) { return { txid: tx.txid, tweak: Buffer.from(tweak).toString('hex'), outputs }; } +let mempoolInit = false; async function mempoolSync() { try { const txids = await rpc('getrawmempool', []); const inPool = new Set(txids); + if (!mempoolInit) { + mempoolInit = true; + // Don't scan a large (mainnet) backlog on startup — that's thousands of + // getrawtransaction calls in a burst on the node. Mark it seen and watch + // only new arrivals. A small (regtest) mempool is cheap, so scan it. + if (txids.length > 200) { for (const txid of txids) mempoolSeen.set(txid, null); return; } + } let changed = false; for (const txid of txids) { if (mempoolSeen.has(txid)) continue; -- cgit v1.2.3