Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/setup_common.cpp
Show First 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | ChainTestingSetup::~ChainTestingSetup() { | ||||
m_node.banman.reset(); | m_node.banman.reset(); | ||||
m_node.addrman.reset(); | m_node.addrman.reset(); | ||||
m_node.args = nullptr; | m_node.args = nullptr; | ||||
m_node.mempool.reset(); | m_node.mempool.reset(); | ||||
m_node.scheduler.reset(); | m_node.scheduler.reset(); | ||||
m_node.chainman.reset(); | m_node.chainman.reset(); | ||||
} | } | ||||
void TestingSetup::LoadVerifyActivateChainstate(const Config &config) { | void TestingSetup::LoadVerifyActivateChainstate() { | ||||
auto &chainman{*Assert(m_node.chainman)}; | auto &chainman{*Assert(m_node.chainman)}; | ||||
node::ChainstateLoadOptions options; | node::ChainstateLoadOptions options; | ||||
options.mempool = Assert(m_node.mempool.get()); | options.mempool = Assert(m_node.mempool.get()); | ||||
options.block_tree_db_in_memory = m_block_tree_db_in_memory; | options.block_tree_db_in_memory = m_block_tree_db_in_memory; | ||||
options.coins_db_in_memory = m_coins_db_in_memory; | options.coins_db_in_memory = m_coins_db_in_memory; | ||||
options.reindex = node::fReindex; | options.reindex = node::fReindex; | ||||
options.reindex_chainstate = | options.reindex_chainstate = | ||||
m_args.GetBoolArg("-reindex-chainstate", false); | m_args.GetBoolArg("-reindex-chainstate", false); | ||||
options.prune = chainman.m_blockman.IsPruneMode(); | options.prune = chainman.m_blockman.IsPruneMode(); | ||||
options.check_blocks = | options.check_blocks = | ||||
m_args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS); | m_args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS); | ||||
options.check_level = m_args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL); | options.check_level = m_args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL); | ||||
options.require_full_verification = | options.require_full_verification = | ||||
m_args.IsArgSet("-checkblocks") || m_args.IsArgSet("-checklevel"); | m_args.IsArgSet("-checkblocks") || m_args.IsArgSet("-checklevel"); | ||||
auto [status, error] = LoadChainstate(chainman, m_cache_sizes, options); | auto [status, error] = LoadChainstate(chainman, m_cache_sizes, options); | ||||
assert(status == node::ChainstateLoadStatus::SUCCESS); | assert(status == node::ChainstateLoadStatus::SUCCESS); | ||||
std::tie(status, error) = VerifyLoadedChainstate(chainman, options, config); | std::tie(status, error) = VerifyLoadedChainstate(chainman, options); | ||||
assert(status == node::ChainstateLoadStatus::SUCCESS); | assert(status == node::ChainstateLoadStatus::SUCCESS); | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!chainman.ActiveChainstate().ActivateBestChain(state)) { | if (!chainman.ActiveChainstate().ActivateBestChain(state)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
strprintf("ActivateBestChain failed. (%s)", state.ToString())); | strprintf("ActivateBestChain failed. (%s)", state.ToString())); | ||||
} | } | ||||
} | } | ||||
Show All 17 Lines | TestingSetup::TestingSetup(const std::string &chainName, | ||||
* handled in bitcoind's init path, but unit tests do not trigger this | * handled in bitcoind's init path, but unit tests do not trigger this | ||||
* codepath, so we call it explicitly as part of setup. | * codepath, so we call it explicitly as part of setup. | ||||
*/ | */ | ||||
std::string rpcWarmupStatus; | std::string rpcWarmupStatus; | ||||
if (RPCIsInWarmup(&rpcWarmupStatus)) { | if (RPCIsInWarmup(&rpcWarmupStatus)) { | ||||
SetRPCWarmupFinished(); | SetRPCWarmupFinished(); | ||||
} | } | ||||
LoadVerifyActivateChainstate(config); | LoadVerifyActivateChainstate(); | ||||
m_node.addrman = std::make_unique<AddrMan>( | m_node.addrman = std::make_unique<AddrMan>( | ||||
/* asmap= */ std::vector<bool>(), /* consistency_check_ratio= */ 0); | /* asmap= */ std::vector<bool>(), /* consistency_check_ratio= */ 0); | ||||
m_node.banman = std::make_unique<BanMan>( | m_node.banman = std::make_unique<BanMan>( | ||||
m_args.GetDataDirBase() / "banlist.dat", config.GetChainParams(), | m_args.GetDataDirBase() / "banlist.dat", config.GetChainParams(), | ||||
nullptr, DEFAULT_MISBEHAVING_BANTIME); | nullptr, DEFAULT_MISBEHAVING_BANTIME); | ||||
// Deterministic randomness for tests. | // Deterministic randomness for tests. | ||||
m_node.connman = | m_node.connman = | ||||
▲ Show 20 Lines • Show All 321 Lines • Show Last 20 Lines |