Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_chainstatemanager_tests.cpp
Show All 16 Lines | |||||
BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, TestingSetup) | BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, TestingSetup) | ||||
//! Basic tests for ChainstateManager. | //! Basic tests for ChainstateManager. | ||||
//! | //! | ||||
//! First create a legacy (IBD) chainstate, then create a snapshot chainstate. | //! First create a legacy (IBD) chainstate, then create a snapshot chainstate. | ||||
BOOST_AUTO_TEST_CASE(chainstatemanager) { | BOOST_AUTO_TEST_CASE(chainstatemanager) { | ||||
ChainstateManager manager; | ChainstateManager manager; | ||||
CTxMemPool mempool; | |||||
std::vector<CChainState *> chainstates; | std::vector<CChainState *> chainstates; | ||||
const CChainParams &chainparams = Params(); | const CChainParams &chainparams = Params(); | ||||
// Create a legacy (IBD) chainstate. | // Create a legacy (IBD) chainstate. | ||||
// | // | ||||
CChainState &c1 = | CChainState &c1 = | ||||
*WITH_LOCK(::cs_main, return &manager.InitializeChainstate()); | *WITH_LOCK(::cs_main, return &manager.InitializeChainstate(mempool)); | ||||
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); | ||||
WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23)); | WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23)); | ||||
BOOST_CHECK(!manager.IsSnapshotActive()); | BOOST_CHECK(!manager.IsSnapshotActive()); | ||||
BOOST_CHECK(!manager.IsSnapshotValidated()); | BOOST_CHECK(!manager.IsSnapshotValidated()); | ||||
Show All 11 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. | ||||
// | // | ||||
CChainState &c2 = *WITH_LOCK( | CChainState &c2 = | ||||
::cs_main, | *WITH_LOCK(::cs_main, return &manager.InitializeChainstate( | ||||
return &manager.InitializeChainstate(BlockHash{GetRandHash()})); | mempool, BlockHash{GetRandHash()})); | ||||
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 All 35 Lines | BOOST_AUTO_TEST_CASE(chainstatemanager) { | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
WITH_LOCK(::cs_main, manager.Unload()); | WITH_LOCK(::cs_main, manager.Unload()); | ||||
} | } | ||||
//! Test rebalancing the caches associated with each chainstate. | //! Test rebalancing the caches associated with each chainstate. | ||||
BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) { | BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) { | ||||
ChainstateManager manager; | ChainstateManager manager; | ||||
CTxMemPool mempool; | |||||
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. | ||||
// | // | ||||
CChainState &c1 = | CChainState &c1 = | ||||
*WITH_LOCK(cs_main, return &manager.InitializeChainstate()); | *WITH_LOCK(cs_main, return &manager.InitializeChainstate(mempool)); | ||||
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. | ||||
// | // | ||||
CChainState &c2 = *WITH_LOCK(cs_main, return &manager.InitializeChainstate( | CChainState &c2 = | ||||
BlockHash{GetRandHash()})); | *WITH_LOCK(cs_main, return &manager.InitializeChainstate( | ||||
mempool, BlockHash{GetRandHash()})); | |||||
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 |