refactor: extract LargeCoinsCacheThreshold from GetCoinsCacheSizeState

Move-only commit, enabled reusing the large cache size calculation logic later. The only difference is the removal of the `static` keyword  (since in a constexpr function it's a C++23 extension)
This commit is contained in:
Lőrinc
2025-07-19 17:19:21 -07:00
parent 321984705d
commit 1b40dc02a6
2 changed files with 11 additions and 6 deletions

View File

@@ -2786,15 +2786,10 @@ CoinsCacheSizeState Chainstate::GetCoinsCacheSizeState(
int64_t nTotalSpace =
max_coins_cache_size_bytes + std::max<int64_t>(int64_t(max_mempool_size_bytes) - nMempoolUsage, 0);
//! No need to periodic flush if at least this much space still available.
static constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = 10 * 1024 * 1024; // 10MB
int64_t large_threshold =
std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE_BYTES);
if (cacheSize > nTotalSpace) {
LogPrintf("Cache size (%s) exceeds total space (%s)\n", cacheSize, nTotalSpace);
return CoinsCacheSizeState::CRITICAL;
} else if (cacheSize > large_threshold) {
} else if (cacheSize > LargeCoinsCacheThreshold(nTotalSpace)) {
return CoinsCacheSizeState::LARGE;
}
return CoinsCacheSizeState::OK;

View File

@@ -35,6 +35,7 @@
#include <util/translation.h>
#include <versionbits.h>
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <map>
@@ -503,6 +504,15 @@ enum class CoinsCacheSizeState
OK = 0
};
constexpr int64_t LargeCoinsCacheThreshold(int64_t nTotalSpace) noexcept
{
//! No need to periodic flush if at least this much space still available.
constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = 10 * 1024 * 1024; // 10MB
int64_t large_threshold =
std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE_BYTES);
return large_threshold;
}
/**
* Chainstate stores and provides an API to update our local knowledge of the
* current best chain.