mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-03 13:44:42 -05:00
test/setup: Use LoadChainstate
This commit coalesces the chainstate loading sequence between our unit test and non-unit test init codepaths.
This commit is contained in:
parent
c541da0d62
commit
9a5a5a3d08
2 changed files with 20 additions and 10 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue