mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-05-17 23:56:39 +00: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
@ -17,6 +17,8 @@
|
|||||||
#include <net_processing.h>
|
#include <net_processing.h>
|
||||||
#include <node/miner.h>
|
#include <node/miner.h>
|
||||||
#include <noui.h>
|
#include <noui.h>
|
||||||
|
#include <node/blockstorage.h> // for fReindex, fPruneMode
|
||||||
|
#include <node/chainstate.h> // for LoadChainstate
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <pow.h>
|
#include <pow.h>
|
||||||
#include <rpc/blockchain.h>
|
#include <rpc/blockchain.h>
|
||||||
@ -24,6 +26,7 @@
|
|||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <script/sigcache.h>
|
#include <script/sigcache.h>
|
||||||
|
#include <shutdown.h> // for ShutdownRequested
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <txdb.h>
|
#include <txdb.h>
|
||||||
#include <util/strencodings.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.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
|
||||||
m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1);
|
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 = 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.
|
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
|
||||||
constexpr int script_check_threads = 2;
|
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.
|
// instead of unit tests, but for now we need these here.
|
||||||
RegisterAllCoreRPCCommands(tableRPC);
|
RegisterAllCoreRPCCommands(tableRPC);
|
||||||
|
|
||||||
m_node.chainman->InitializeChainstate(m_node.mempool.get());
|
auto rv = LoadChainstate(fReindex.load(),
|
||||||
m_node.chainman->ActiveChainstate().InitCoinsDB(
|
*Assert(m_node.chainman.get()),
|
||||||
/*cache_size_bytes=*/1 << 23, /*in_memory=*/true, /*should_wipe=*/false);
|
Assert(m_node.mempool.get()),
|
||||||
assert(!m_node.chainman->ActiveChainstate().CanFlushToDisk());
|
fPruneMode,
|
||||||
m_node.chainman->ActiveChainstate().InitCoinsCache(1 << 23);
|
chainparams.GetConsensus(),
|
||||||
assert(m_node.chainman->ActiveChainstate().CanFlushToDisk());
|
m_args.GetBoolArg("-reindex-chainstate", false),
|
||||||
if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock()) {
|
m_cache_sizes.block_tree_db,
|
||||||
throw std::runtime_error("LoadGenesisBlock failed.");
|
m_cache_sizes.coins_db,
|
||||||
}
|
m_cache_sizes.coins,
|
||||||
|
true,
|
||||||
|
true);
|
||||||
|
assert(!rv.has_value());
|
||||||
|
|
||||||
BlockValidationState state;
|
BlockValidationState state;
|
||||||
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
|
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
#include <node/caches.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <pubkey.h>
|
#include <pubkey.h>
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
@ -89,6 +90,7 @@ struct BasicTestingSetup {
|
|||||||
* initialization behaviour.
|
* initialization behaviour.
|
||||||
*/
|
*/
|
||||||
struct ChainTestingSetup : public BasicTestingSetup {
|
struct ChainTestingSetup : public BasicTestingSetup {
|
||||||
|
CacheSizes m_cache_sizes{};
|
||||||
|
|
||||||
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
|
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
|
||||||
~ChainTestingSetup();
|
~ChainTestingSetup();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user