diff --git a/src/validation.cpp b/src/validation.cpp index b62691ca4c0..c8c496a59ab 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2786,15 +2786,10 @@ CoinsCacheSizeState Chainstate::GetCoinsCacheSizeState( int64_t nTotalSpace = max_coins_cache_size_bytes + std::max(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; diff --git a/src/validation.h b/src/validation.h index c25dd2de2d9..8998dccedcf 100644 --- a/src/validation.h +++ b/src/validation.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -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.