MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / CalculateCacheSizes

Function CalculateCacheSizes

src/node/caches.cpp:57–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
58{
59 size_t total_cache{CalculateDbCacheBytes(args)};
60
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 from LevelDB cache, but the
66 // working set for a typical 2-week offline gap is ~200kiB, well within 5%
67 // of the total cache.
68 // - txospenderindex (5%): serves gettxspendingprevout RPCs with very
69 // specific, rarely repeated outpoint queries.
70 // - coinstatsindex: intentionally not included here, since usage pattern
71 // does not seem to suggest it would be necessary to cache.
72 IndexCacheSizes index_sizes;
73 index_sizes.tx_index = std::min(total_cache * 10 / 100, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE : 0);
74 index_sizes.txospender_index = std::min(total_cache * 5 / 100, args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX) ? MAX_TXOSPENDER_INDEX_CACHE : 0);
75 if (n_indexes > 0) {
76 size_t max_cache = std::min(total_cache * 5 / 100, MAX_FILTER_INDEX_CACHE);
77 index_sizes.filter_index = max_cache / n_indexes;
78 total_cache -= index_sizes.filter_index * n_indexes;
79 }
80 total_cache -= index_sizes.tx_index;
81 total_cache -= index_sizes.txospender_index;
82 return {index_sizes, kernel::CacheSizes{total_cache}};
83}
84
85void LogOversizedDbCache(const ArgsManager& args) noexcept
86{

Callers 2

AppInitMainFunction · 0.85
ChainTestingSetupClass · 0.85

Calls 2

CalculateDbCacheBytesFunction · 0.85
GetBoolArgMethod · 0.80

Tested by

no test coverage detected