10#include <boost/test/unit_test.hpp>
24 chainstate.InitCoinsDB( 1 << 10,
true,
false);
27 constexpr bool is_64_bit =
sizeof(
void*) == 8;
30 auto& view = chainstate.CoinsTip();
40 coins_view.AddCoin(outp, std::move(newcoin),
false);
49 constexpr unsigned int COIN_SIZE = is_64_bit ? 80 : 64;
52 BOOST_TEST_MESSAGE(
"CCoinsViewCache memory usage: " << view.DynamicMemoryUsage());
55 constexpr size_t MAX_COINS_CACHE_BYTES = 1024;
59 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
65 if (view.DynamicMemoryUsage() != 32 && view.DynamicMemoryUsage() != 16) {
68 for (
int i{0}; i < 1000; ++i) {
74 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
77 BOOST_TEST_MESSAGE(
"Exiting cache flush tests early due to unsupported arch");
81 print_view_mem_usage(view);
88 constexpr int COINS_UNTIL_CRITICAL{3};
90 for (
int i{0}; i < COINS_UNTIL_CRITICAL; ++i) {
92 print_view_mem_usage(view);
95 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
100 for (
int i{0}; i < 4; ++i) {
102 print_view_mem_usage(view);
103 if (chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0) ==
110 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
115 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
118 for (
int i{0}; i < 3; ++i) {
120 print_view_mem_usage(view);
122 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
129 print_view_mem_usage(view);
133 float usage_percentage = (float)view.DynamicMemoryUsage() / (MAX_COINS_CACHE_BYTES + (1 << 10));
134 BOOST_TEST_MESSAGE(
"CoinsTip usage percentage: " << usage_percentage);
138 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 1 << 10),
143 for (
int i{0}; i < 1000; ++i) {
146 chainstate.GetCoinsCacheSizeState(),
154 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
159 print_view_mem_usage(view);
162 chainstate.GetCoinsCacheSizeState(MAX_COINS_CACHE_BYTES, 0),
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#define Assert(val)
Identity function.
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
CChainState stores and provides an API to update our local knowledge of the current best chain.
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.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
CTxOut out
unspent transaction output
uint32_t nHeight
at which height this containing transaction was included in the active block chain
void assign(size_type n, const T &val)
static void add_coin(const CAmount &nValue, int nInput, std::vector< OutputGroup > &set)
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static uint256 InsecureRand256()
static uint32_t InsecureRand32()
Testing setup that performs all steps up until right before ChainstateManager gets initialized.
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
@ 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.