11#include <boost/test/unit_test.hpp>
24 constexpr bool is_64_bit =
sizeof(
void*) == 8;
27 auto& view = chainstate.CoinsTip();
33 constexpr unsigned int COIN_SIZE = is_64_bit ? 80 : 64;
36 BOOST_TEST_MESSAGE(
"CCoinsViewCache memory usage: " << view.DynamicMemoryUsage());
40 constexpr size_t MAX_COINS_CACHE_BYTES = 262144 + 512;
49 if (view.DynamicMemoryUsage() != 32 && view.DynamicMemoryUsage() != 16) {
52 for (
int i{0}; i < 1000; ++i) {
58 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
61 BOOST_TEST_MESSAGE(
"Exiting cache flush tests early due to unsupported arch");
65 print_view_mem_usage(view);
72 constexpr int COINS_UNTIL_CRITICAL{3};
76 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
79 for (
int i{0}; i < COINS_UNTIL_CRITICAL; ++i) {
81 print_view_mem_usage(view);
87 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
92 for (
int i{0}; i < 4; ++i) {
94 print_view_mem_usage(view);
95 if (chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0) ==
102 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
107 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 19),
110 for (
int i{0}; i < 3; ++i) {
112 print_view_mem_usage(view);
114 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 19),
121 print_view_mem_usage(view);
125 float usage_percentage = (float)view.DynamicMemoryUsage() / (MAX_COINS_CACHE_BYTES + (1 << 10));
126 BOOST_TEST_MESSAGE(
"CoinsTip usage percentage: " << usage_percentage);
130 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
135 for (
int i{0}; i < 1000; ++i) {
138 chainstate.GetCoinsCacheSizeState(),
145 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
148 view.SetBestBlock(m_rng.rand256());
150 print_view_mem_usage(view);
153 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
CCoinsView that adds a memory cache for transactions to another CCoinsView.
An outpoint - a combination of a transaction hash and an index n into its vout.
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)
#define BOOST_CHECK(expr)
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.
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
Test utilities for detecting when we need to flush the coins cache based on estimated memory usage.