7 #include <validation.h> 9 #include <boost/test/unit_test.hpp> 11 BOOST_FIXTURE_TEST_SUITE(validation_flush_tests,
TestingSetup)
22 constexpr
bool is_64_bit =
sizeof(
void*) == 8;
25 auto& view = chainstate.CoinsTip();
35 coins_view.AddCoin(outp, std::move(newcoin),
false);
44 constexpr
unsigned int COIN_SIZE = is_64_bit ? 80 : 64;
47 BOOST_TEST_MESSAGE(
"CCoinsViewCache memory usage: " << view.DynamicMemoryUsage());
50 constexpr
size_t MAX_COINS_CACHE_BYTES = 1024;
54 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
60 if (view.DynamicMemoryUsage() != 32 && view.DynamicMemoryUsage() != 16) {
63 for (
int i{0}; i < 1000; ++i) {
69 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
72 BOOST_TEST_MESSAGE(
"Exiting cache flush tests early due to unsupported arch");
76 print_view_mem_usage(view);
83 constexpr
int COINS_UNTIL_CRITICAL{3};
85 for (
int i{0}; i < COINS_UNTIL_CRITICAL; ++i) {
87 print_view_mem_usage(view);
90 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
95 for (
int i{0}; i < 4; ++i) {
97 print_view_mem_usage(view);
98 if (chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0) ==
105 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
110 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
113 for (
int i{0}; i < 3; ++i) {
115 print_view_mem_usage(view);
117 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
124 print_view_mem_usage(view);
128 float usage_percentage = (float)view.DynamicMemoryUsage() / (MAX_COINS_CACHE_BYTES + (1 << 10));
129 BOOST_TEST_MESSAGE(
"CoinsTip usage percentage: " << usage_percentage);
133 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
138 for (
int i{0}; i < 1000; ++i) {
141 chainstate.GetCoinsCacheSizeState(),
149 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
154 print_view_mem_usage(view);
157 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
void assign(size_type n, const T &val)
The cache is at >= 90% capacity.
CTxOut out
unspent transaction output
The coins cache is in immediate need of a flush.
static uint32_t InsecureRand32()
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Chainstate stores and provides an API to update our local knowledge of the current best chain...
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
Test utilities for detecting when we need to flush the coins cache based on estimated memory usage...
An outpoint - a combination of a transaction hash and an index n into its vout.
static void add_coin(const CAmount &nValue, int nInput, std::vector< OutputGroup > &set)
#define BOOST_CHECK_EQUAL(v1, v2)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
static uint256 InsecureRand256()
std::unique_ptr< ChainstateManager > chainman
Testing setup that configures a complete environment.
#define BOOST_CHECK(expr)