mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-25 03:41:05 +02:00
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:
@@ -2786,15 +2786,10 @@ CoinsCacheSizeState Chainstate::GetCoinsCacheSizeState(
|
|||||||
int64_t nTotalSpace =
|
int64_t nTotalSpace =
|
||||||
max_coins_cache_size_bytes + std::max<int64_t>(int64_t(max_mempool_size_bytes) - nMempoolUsage, 0);
|
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) {
|
if (cacheSize > nTotalSpace) {
|
||||||
LogPrintf("Cache size (%s) exceeds total space (%s)\n", cacheSize, nTotalSpace);
|
LogPrintf("Cache size (%s) exceeds total space (%s)\n", cacheSize, nTotalSpace);
|
||||||
return CoinsCacheSizeState::CRITICAL;
|
return CoinsCacheSizeState::CRITICAL;
|
||||||
} else if (cacheSize > large_threshold) {
|
} else if (cacheSize > LargeCoinsCacheThreshold(nTotalSpace)) {
|
||||||
return CoinsCacheSizeState::LARGE;
|
return CoinsCacheSizeState::LARGE;
|
||||||
}
|
}
|
||||||
return CoinsCacheSizeState::OK;
|
return CoinsCacheSizeState::OK;
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <versionbits.h>
|
#include <versionbits.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -503,6 +504,15 @@ enum class CoinsCacheSizeState
|
|||||||
OK = 0
|
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
|
* Chainstate stores and provides an API to update our local knowledge of the
|
||||||
* current best chain.
|
* current best chain.
|
||||||
|
Reference in New Issue
Block a user