Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/setup_common.cpp
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | TestingSetup::TestingSetup(const std::string &chainName, | ||||
// We have to run a scheduler thread to prevent ActivateBestChain | // We have to run a scheduler thread to prevent ActivateBestChain | ||||
// from blocking due to queue overrun. | // from blocking due to queue overrun. | ||||
threadGroup.create_thread([&] { m_node.scheduler->serviceQueue(); }); | threadGroup.create_thread([&] { m_node.scheduler->serviceQueue(); }); | ||||
GetMainSignals().RegisterBackgroundSignalScheduler(*m_node.scheduler); | GetMainSignals().RegisterBackgroundSignalScheduler(*m_node.scheduler); | ||||
pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | pblocktree.reset(new CBlockTreeDB(1 << 20, true)); | ||||
m_node.mempool = &::g_mempool; | |||||
m_node.mempool->setSanityCheck(1.0); | |||||
m_node.chainman = &::g_chainman; | m_node.chainman = &::g_chainman; | ||||
m_node.chainman->InitializeChainstate(); | m_node.chainman->InitializeChainstate(*m_node.mempool); | ||||
::ChainstateActive().InitCoinsDB( | ::ChainstateActive().InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | /* cache_size_bytes */ 1 << 23, /* in_memory */ true, | ||||
/* should_wipe */ false); | /* should_wipe */ false); | ||||
assert(!::ChainstateActive().CanFlushToDisk()); | assert(!::ChainstateActive().CanFlushToDisk()); | ||||
::ChainstateActive().InitCoinsCache(1 << 23); | ::ChainstateActive().InitCoinsCache(1 << 23); | ||||
assert(::ChainstateActive().CanFlushToDisk()); | assert(::ChainstateActive().CanFlushToDisk()); | ||||
if (!LoadGenesisBlock(chainparams)) { | if (!LoadGenesisBlock(chainparams)) { | ||||
throw std::runtime_error("LoadGenesisBlock failed."); | throw std::runtime_error("LoadGenesisBlock failed."); | ||||
} | } | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!ActivateBestChain(config, state)) { | if (!ActivateBestChain(config, state)) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
strprintf("ActivateBestChain failed. (%s)", state.ToString())); | strprintf("ActivateBestChain failed. (%s)", state.ToString())); | ||||
} | } | ||||
} | } | ||||
constexpr int script_check_threads = 2; | constexpr int script_check_threads = 2; | ||||
for (int i = 0; i < script_check_threads; ++i) { | for (int i = 0; i < script_check_threads; ++i) { | ||||
threadGroup.create_thread([i]() { return ThreadScriptCheck(i); }); | threadGroup.create_thread([i]() { return ThreadScriptCheck(i); }); | ||||
} | } | ||||
m_node.mempool = &::g_mempool; | |||||
m_node.mempool->setSanityCheck(1.0); | |||||
m_node.banman = | m_node.banman = | ||||
std::make_unique<BanMan>(GetDataDir() / "banlist.dat", chainparams, | std::make_unique<BanMan>(GetDataDir() / "banlist.dat", chainparams, | ||||
nullptr, DEFAULT_MISBEHAVING_BANTIME); | nullptr, DEFAULT_MISBEHAVING_BANTIME); | ||||
// Deterministic randomness for tests. | // Deterministic randomness for tests. | ||||
m_node.connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | m_node.connman = std::make_unique<CConnman>(config, 0x1337, 0x1337); | ||||
m_node.peerman = std::make_unique<PeerManager>( | m_node.peerman = std::make_unique<PeerManager>( | ||||
chainparams, *m_node.connman, m_node.banman.get(), *m_node.scheduler, | chainparams, *m_node.connman, m_node.banman.get(), *m_node.scheduler, | ||||
*m_node.chainman, *m_node.mempool); | *m_node.chainman, *m_node.mempool); | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |