From d06dabf26bea7d9ca8d635e8338f64aec74c56a8 Mon Sep 17 00:00:00 2001 From: Sebastian van Staa Date: Fri, 20 Feb 2026 13:18:54 +0100 Subject: [PATCH 1/2] node: allocate index caches proportional to usage patterns add comment explaining coinstatsindex cache exclusion update cache allocations to 10%/5%/5% --- src/node/caches.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/node/caches.cpp b/src/node/caches.cpp index cb8afbc967d..d1a54b95f81 100644 --- a/src/node/caches.cpp +++ b/src/node/caches.cpp @@ -58,16 +58,25 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) { size_t total_cache{CalculateDbCacheBytes(args)}; + // Allocate proportional to usage pattern benefit: + // - txindex (10%): serves getrawtransaction RPCs with mostly unique, + // non-repetitive lookups across the entire blockchain. + // - blockfilterindex (5%): serves BIP 157 light clients that repeatedly + // query recent blocks, benefiting most from LevelDB cache. + // - txospenderindex (5%): serves gettxspendingprevout RPCs with very + // specific, rarely repeated outpoint queries. + // - coinstatsindex: intentionally not included here, since usage pattern + // does not seem to suggest it would be necessary to cache. IndexCacheSizes index_sizes; - index_sizes.tx_index = std::min(total_cache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE : 0); - total_cache -= index_sizes.tx_index; - index_sizes.txospender_index = std::min(total_cache / 8, args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX) ? MAX_TXOSPENDER_INDEX_CACHE : 0); - total_cache -= index_sizes.txospender_index; + index_sizes.tx_index = std::min(total_cache * 10 / 100, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE : 0); + index_sizes.txospender_index = std::min(total_cache * 5 / 100, args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX) ? MAX_TXOSPENDER_INDEX_CACHE : 0); if (n_indexes > 0) { - size_t max_cache = std::min(total_cache / 8, MAX_FILTER_INDEX_CACHE); + size_t max_cache = std::min(total_cache * 5 / 100, MAX_FILTER_INDEX_CACHE); index_sizes.filter_index = max_cache / n_indexes; total_cache -= index_sizes.filter_index * n_indexes; } + total_cache -= index_sizes.tx_index; + total_cache -= index_sizes.txospender_index; return {index_sizes, kernel::CacheSizes{total_cache}}; } From 5a2e3592137d595fb5fd0f9d66c9cac6c020d7bd Mon Sep 17 00:00:00 2001 From: Sebastian van Staa Date: Mon, 4 May 2026 21:21:29 +0200 Subject: [PATCH 2/2] clarify blockfilterindex cache allocation rationale --- src/node/caches.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node/caches.cpp b/src/node/caches.cpp index d1a54b95f81..03c58648b7f 100644 --- a/src/node/caches.cpp +++ b/src/node/caches.cpp @@ -62,7 +62,9 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) // - txindex (10%): serves getrawtransaction RPCs with mostly unique, // non-repetitive lookups across the entire blockchain. // - blockfilterindex (5%): serves BIP 157 light clients that repeatedly - // query recent blocks, benefiting most from LevelDB cache. + // query recent blocks, benefiting from LevelDB cache, but the + // working set for a typical 2-week offline gap is ~200kiB, well within 5% + // of the total cache. // - txospenderindex (5%): serves gettxspendingprevout RPCs with very // specific, rarely repeated outpoint queries. // - coinstatsindex: intentionally not included here, since usage pattern