9 #include <validation.h>
11 #include <boost/test/unit_test.hpp>
13 BOOST_FIXTURE_TEST_SUITE(validation_flush_tests,
TestingSetup)
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());
39 constexpr
size_t MAX_COINS_CACHE_BYTES = 1024;
43 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
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};
74 for (
int i{0}; i < COINS_UNTIL_CRITICAL; ++i) {
76 print_view_mem_usage(view);
79 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
84 for (
int i{0}; i < 4; ++i) {
86 print_view_mem_usage(view);
87 if (chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0) ==
94 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
99 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
102 for (
int i{0}; i < 3; ++i) {
104 print_view_mem_usage(view);
106 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
113 print_view_mem_usage(view);
117 float usage_percentage = (float)view.DynamicMemoryUsage() / (MAX_COINS_CACHE_BYTES + (1 << 10));
118 BOOST_TEST_MESSAGE(
"CoinsTip usage percentage: " << usage_percentage);
122 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
127 for (
int i{0}; i < 1000; ++i) {
130 chainstate.GetCoinsCacheSizeState(),
138 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
143 print_view_mem_usage(view);
146 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_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(CCoinsViewCache &coins_view)
Create a Coin with DynamicMemoryUsage of 80 bytes and add it to the given view.
static uint256 InsecureRand256()
@ 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.