Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_chainstatemanager_tests.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(chainstatemanager) { | ||||
auto exp_tip = c1.m_chain.Tip(); | auto exp_tip = c1.m_chain.Tip(); | ||||
BOOST_CHECK_EQUAL(active_tip, exp_tip); | BOOST_CHECK_EQUAL(active_tip, exp_tip); | ||||
auto &validated_cs = manager.ValidatedChainstate(); | auto &validated_cs = manager.ValidatedChainstate(); | ||||
BOOST_CHECK_EQUAL(&validated_cs, &c1); | BOOST_CHECK_EQUAL(&validated_cs, &c1); | ||||
// Create a snapshot-based chainstate. | // Create a snapshot-based chainstate. | ||||
// | // | ||||
ENTER_CRITICAL_SECTION(cs_main); | |||||
CChainState &c2 = *WITH_LOCK( | CChainState &c2 = *WITH_LOCK( | ||||
::cs_main, | ::cs_main, | ||||
return &manager.InitializeChainstate(BlockHash{GetRandHash()})); | return &manager.InitializeChainstate(BlockHash{GetRandHash()})); | ||||
LEAVE_CRITICAL_SECTION(cs_main); | |||||
chainstates.push_back(&c2); | chainstates.push_back(&c2); | ||||
c2.InitCoinsDB( | c2.InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | /* cache_size_bytes */ 1 << 23, /* in_memory */ true, | ||||
/* should_wipe */ false); | /* should_wipe */ false); | ||||
WITH_LOCK(::cs_main, c2.InitCoinsCache(1 << 23)); | WITH_LOCK(::cs_main, c2.InitCoinsCache(1 << 23)); | ||||
// Unlike c1, which doesn't have any blocks. Gets us different tip, height. | // Unlike c1, which doesn't have any blocks. Gets us different tip, height. | ||||
c2.LoadGenesisBlock(chainparams); | c2.LoadGenesisBlock(chainparams); | ||||
BlockValidationState _; | BlockValidationState _; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) { | ||||
size_t max_cache = 10000; | size_t max_cache = 10000; | ||||
manager.m_total_coinsdb_cache = max_cache; | manager.m_total_coinsdb_cache = max_cache; | ||||
manager.m_total_coinstip_cache = max_cache; | manager.m_total_coinstip_cache = max_cache; | ||||
std::vector<CChainState *> chainstates; | std::vector<CChainState *> chainstates; | ||||
// Create a legacy (IBD) chainstate. | // Create a legacy (IBD) chainstate. | ||||
// | // | ||||
ENTER_CRITICAL_SECTION(cs_main); | CChainState &c1 = | ||||
CChainState &c1 = manager.InitializeChainstate(); | *WITH_LOCK(cs_main, return &manager.InitializeChainstate()); | ||||
LEAVE_CRITICAL_SECTION(cs_main); | |||||
chainstates.push_back(&c1); | chainstates.push_back(&c1); | ||||
c1.InitCoinsDB( | c1.InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | /* cache_size_bytes */ 1 << 23, /* in_memory */ true, | ||||
/* should_wipe */ false); | /* should_wipe */ false); | ||||
{ | { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
c1.InitCoinsCache(1 << 23); | c1.InitCoinsCache(1 << 23); | ||||
c1.CoinsTip().SetBestBlock(BlockHash{InsecureRand256()}); | c1.CoinsTip().SetBestBlock(BlockHash{InsecureRand256()}); | ||||
manager.MaybeRebalanceCaches(); | manager.MaybeRebalanceCaches(); | ||||
} | } | ||||
BOOST_CHECK_EQUAL(c1.m_coinstip_cache_size_bytes, max_cache); | BOOST_CHECK_EQUAL(c1.m_coinstip_cache_size_bytes, max_cache); | ||||
BOOST_CHECK_EQUAL(c1.m_coinsdb_cache_size_bytes, max_cache); | BOOST_CHECK_EQUAL(c1.m_coinsdb_cache_size_bytes, max_cache); | ||||
// Create a snapshot-based chainstate. | // Create a snapshot-based chainstate. | ||||
// | // | ||||
ENTER_CRITICAL_SECTION(cs_main); | CChainState &c2 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate( | ||||
CChainState &c2 = manager.InitializeChainstate(BlockHash{GetRandHash()}); | BlockHash{GetRandHash()})); | ||||
LEAVE_CRITICAL_SECTION(cs_main); | |||||
chainstates.push_back(&c2); | chainstates.push_back(&c2); | ||||
c2.InitCoinsDB( | c2.InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | /* cache_size_bytes */ 1 << 23, /* in_memory */ true, | ||||
/* should_wipe */ false); | /* should_wipe */ false); | ||||
{ | { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
c2.InitCoinsCache(1 << 23); | c2.InitCoinsCache(1 << 23); | ||||
Show All 13 Lines |