Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_flush_tests.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | auto add_coin = [](CCoinsViewCache &coins_view) -> COutPoint { | ||||
return outp; | return outp; | ||||
}; | }; | ||||
// The number of bytes consumed by coin's heap data, i.e. CScript | // The number of bytes consumed by coin's heap data, i.e. CScript | ||||
// (prevector<28, uint8_t>) when assigned 56 bytes of data per above. | // (prevector<28, uint8_t>) when assigned 56 bytes of data per above. | ||||
// | // | ||||
// See also: Coin::DynamicMemoryUsage(). | // See also: Coin::DynamicMemoryUsage(). | ||||
constexpr int COIN_SIZE = is_64_bit ? 80 : 72; | constexpr unsigned int COIN_SIZE = is_64_bit ? 80 : 72; | ||||
auto print_view_mem_usage = [](CCoinsViewCache &_view) { | auto print_view_mem_usage = [](CCoinsViewCache &_view) { | ||||
BOOST_TEST_MESSAGE( | BOOST_TEST_MESSAGE( | ||||
"CCoinsViewCache memory usage: " << _view.DynamicMemoryUsage()); | "CCoinsViewCache memory usage: " << _view.DynamicMemoryUsage()); | ||||
}; | }; | ||||
constexpr size_t MAX_COINS_CACHE_BYTES = 1024; | constexpr size_t MAX_COINS_CACHE_BYTES = 1024; | ||||
Show All 21 Lines | if (view.DynamicMemoryUsage() != 32 && view.DynamicMemoryUsage() != 16) { | ||||
CoinsCacheSizeState::CRITICAL); | CoinsCacheSizeState::CRITICAL); | ||||
BOOST_TEST_MESSAGE( | BOOST_TEST_MESSAGE( | ||||
"Exiting cache flush tests early due to unsupported arch"); | "Exiting cache flush tests early due to unsupported arch"); | ||||
return; | return; | ||||
} | } | ||||
print_view_mem_usage(view); | print_view_mem_usage(view); | ||||
BOOST_CHECK_EQUAL(view.DynamicMemoryUsage(), is_64_bit ? 32 : 16); | BOOST_CHECK_EQUAL(view.DynamicMemoryUsage(), is_64_bit ? 32U : 16U); | ||||
// We should be able to add COINS_UNTIL_CRITICAL coins to the cache before | // We should be able to add COINS_UNTIL_CRITICAL coins to the cache before | ||||
// going CRITICAL. This is contingent not only on the dynamic memory usage | // going CRITICAL. This is contingent not only on the dynamic memory usage | ||||
// of the Coins that we're adding (COIN_SIZE bytes per), but also on how | // of the Coins that we're adding (COIN_SIZE bytes per), but also on how | ||||
// much memory the cacheCoins (unordered_map) preallocates. | // much memory the cacheCoins (unordered_map) preallocates. | ||||
constexpr int COINS_UNTIL_CRITICAL{3}; | constexpr int COINS_UNTIL_CRITICAL{3}; | ||||
for (int i{0}; i < COINS_UNTIL_CRITICAL; ++i) { | for (int i{0}; i < COINS_UNTIL_CRITICAL; ++i) { | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |