diff options
author | Carl Dong <contact@carldong.me> | 2021-09-21 14:09:23 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-12-07 14:48:49 -0500 |
commit | 9a5a5a3d08b2c130ab9147914739ff3583b0dc84 (patch) | |
tree | 0df4a51dc8b30536ff033456c7cd6b459d5d1ec4 /src | |
parent | c541da0d62eaf5e96eca00d7508899f98bdfc1bc (diff) |
test/setup: Use LoadChainstate
This commit coalesces the chainstate loading sequence between our unit
test and non-unit test init codepaths.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/util/setup_common.cpp | 28 | ||||
-rw-r--r-- | src/test/util/setup_common.h | 2 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index f5cc88f4ce..628cedac19 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -17,6 +17,8 @@ #include <net_processing.h> #include <node/miner.h> #include <noui.h> +#include <node/blockstorage.h> // for fReindex, fPruneMode +#include <node/chainstate.h> // for LoadChainstate #include <policy/fees.h> #include <pow.h> #include <rpc/blockchain.h> @@ -24,6 +26,7 @@ #include <rpc/server.h> #include <scheduler.h> #include <script/sigcache.h> +#include <shutdown.h> // for ShutdownRequested #include <streams.h> #include <txdb.h> #include <util/strencodings.h> @@ -143,8 +146,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(); m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1); + m_cache_sizes = CalculateCacheSizes(m_args); + m_node.chainman = std::make_unique<ChainstateManager>(); - m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true); + m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true); // Start script-checking threads. Set g_parallel_script_checks to true so they are used. constexpr int script_check_threads = 2; @@ -177,15 +182,18 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const // instead of unit tests, but for now we need these here. RegisterAllCoreRPCCommands(tableRPC); - m_node.chainman->InitializeChainstate(m_node.mempool.get()); - m_node.chainman->ActiveChainstate().InitCoinsDB( - /*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false); - assert(!m_node.chainman->ActiveChainstate().CanFlushToDisk()); - m_node.chainman->ActiveChainstate().InitCoinsCache(1 << 23); - assert(m_node.chainman->ActiveChainstate().CanFlushToDisk()); - if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock()) { - throw std::runtime_error("LoadGenesisBlock failed."); - } + auto rv = LoadChainstate(fReindex.load(), + *Assert(m_node.chainman.get()), + Assert(m_node.mempool.get()), + fPruneMode, + chainparams.GetConsensus(), + m_args.GetBoolArg("-reindex-chainstate", false), + m_cache_sizes.block_tree_db, + m_cache_sizes.coins_db, + m_cache_sizes.coins, + true, + true); + assert(!rv.has_value()); BlockValidationState state; if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) { diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 4f2ccb6ebb..df2c8952bc 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -9,6 +9,7 @@ #include <fs.h> #include <key.h> #include <util/system.h> +#include <node/caches.h> #include <node/context.h> #include <pubkey.h> #include <random.h> @@ -89,6 +90,7 @@ struct BasicTestingSetup { * initialization behaviour. */ struct ChainTestingSetup : public BasicTestingSetup { + CacheSizes m_cache_sizes{}; explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}); ~ChainTestingSetup(); |