Skip to content

Commit fa29acc

Browse files
committed
node: allocate index caches proportional to usage patterns
add comment explaining coinstatsindex cache exclusion update cache allocations to 10%/5%/5%
1 parent 04480c2 commit fa29acc

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/node/caches.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,25 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
5858
{
5959
size_t total_cache{CalculateDbCacheBytes(args)};
6060

61+
// Allocate proportional to usage pattern benefit:
62+
// - txindex (10%): serves getrawtransaction RPCs with mostly unique,
63+
// non-repetitive lookups across the entire blockchain.
64+
// - blockfilterindex (5%): serves BIP 157 light clients that repeatedly
65+
// query recent blocks, benefiting most from LevelDB cache.
66+
// - txospenderindex (5%): serves gettxspendingprevout RPCs with very
67+
// specific, rarely repeated outpoint queries.
68+
// - coinstatsindex: intentionally not included here, since usage pattern
69+
// does not seem to suggest it would be necessary to cache.
6170
IndexCacheSizes index_sizes;
62-
index_sizes.tx_index = std::min(total_cache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE : 0);
63-
total_cache -= index_sizes.tx_index;
64-
index_sizes.txospender_index = std::min(total_cache / 8, args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX) ? MAX_TXOSPENDER_INDEX_CACHE : 0);
65-
total_cache -= index_sizes.txospender_index;
71+
index_sizes.tx_index = std::min(total_cache * 10 / 100, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE : 0);
72+
index_sizes.txospender_index = std::min(total_cache * 5 / 100, args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX) ? MAX_TXOSPENDER_INDEX_CACHE : 0);
6673
if (n_indexes > 0) {
67-
size_t max_cache = std::min(total_cache / 8, MAX_FILTER_INDEX_CACHE);
74+
size_t max_cache = std::min(total_cache * 5 / 100, MAX_FILTER_INDEX_CACHE);
6875
index_sizes.filter_index = max_cache / n_indexes;
6976
total_cache -= index_sizes.filter_index * n_indexes;
7077
}
78+
total_cache -= index_sizes.tx_index;
79+
total_cache -= index_sizes.txospender_index;
7180
return {index_sizes, kernel::CacheSizes{total_cache}};
7281
}
7382

0 commit comments

Comments
 (0)