2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2021-2022 The Bitcoin Core developers
|
2021-09-21 11:37:03 -04:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
|
|
#include <node/caches.h>
|
|
|
|
|
|
2023-03-23 12:23:29 +01:00
|
|
|
#include <common/args.h>
|
2022-10-03 15:53:22 +01:00
|
|
|
#include <index/txindex.h>
|
2024-11-22 20:51:34 +01:00
|
|
|
#include <kernel/caches.h>
|
2021-09-21 11:37:03 -04:00
|
|
|
#include <txdb.h>
|
|
|
|
|
|
2024-11-22 20:51:34 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2021-11-12 10:06:00 -05:00
|
|
|
namespace node {
|
2021-09-21 11:37:03 -04:00
|
|
|
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
|
|
|
|
|
{
|
|
|
|
|
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
|
|
|
|
|
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
|
2024-11-22 20:51:34 +01:00
|
|
|
IndexCacheSizes sizes;
|
2021-12-06 16:52:18 -05:00
|
|
|
sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
|
|
|
|
|
nTotalCache -= sizes.tx_index;
|
2021-09-21 11:37:03 -04:00
|
|
|
if (n_indexes > 0) {
|
|
|
|
|
int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
|
2021-12-06 16:52:18 -05:00
|
|
|
sizes.filter_index = max_cache / n_indexes;
|
|
|
|
|
nTotalCache -= sizes.filter_index * n_indexes;
|
2021-09-21 11:37:03 -04:00
|
|
|
}
|
2024-11-22 20:51:34 +01:00
|
|
|
return {sizes, kernel::CacheSizes{static_cast<size_t>(nTotalCache)}};
|
2021-09-21 11:37:03 -04:00
|
|
|
}
|
2021-11-12 10:06:00 -05:00
|
|
|
} // namespace node
|