11#include <boost/test/unit_test.hpp>
26 BOOST_CHECK_LT(view.DynamicMemoryUsage() / (256 * 1024.0), 1.1);
28 constexpr size_t MAX_COINS_BYTES{8_MiB};
29 constexpr size_t MAX_MEMPOOL_BYTES{4_MiB};
30 constexpr size_t MAX_ATTEMPTS{50'000};
33 for (
size_t max_mempool_size_bytes : {
size_t{0}, MAX_MEMPOOL_BYTES}) {
34 const int64_t full_cap{int64_t(MAX_COINS_BYTES + max_mempool_size_bytes)};
38 auto state{chainstate.GetCoinsCacheSizeState(MAX_COINS_BYTES, max_mempool_size_bytes)};
39 for (
size_t i{0}; i < MAX_ATTEMPTS && int64_t(view.DynamicMemoryUsage()) <= large_cap; ++i) {
42 state = chainstate.GetCoinsCacheSizeState(MAX_COINS_BYTES, max_mempool_size_bytes);
46 for (
size_t i{0}; i < MAX_ATTEMPTS && int64_t(view.DynamicMemoryUsage()) <= full_cap; ++i) {
49 state = chainstate.GetCoinsCacheSizeState(MAX_COINS_BYTES, max_mempool_size_bytes);
55 for (
int i{0}; i < 1'000; ++i) {
62 view.SetBestBlock(m_rng.rand256());
63 BOOST_REQUIRE(view.Flush());
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
Testing setup that configures a complete environment.
std::unique_ptr< ChainstateManager > chainman
COutPoint AddTestCoin(FastRandomContext &rng, CCoinsViewCache &coins_view)
Create a Coin with DynamicMemoryUsage of 80 bytes and add it to the given view.
constexpr int64_t LargeCoinsCacheThreshold(int64_t total_space) noexcept
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
Verify that Chainstate::GetCoinsCacheSizeState() switches from OK→LARGE→CRITICAL at the expected util...