aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/init.cpp b/src/init.cpp
index fd7c8d0f80..0427368e70 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -31,6 +31,7 @@
#include <net_processing.h>
#include <netbase.h>
#include <node/context.h>
+#include <node/ui_interface.h>
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/policy.h>
@@ -48,8 +49,8 @@
#include <torcontrol.h>
#include <txdb.h>
#include <txmempool.h>
-#include <ui_interface.h>
#include <util/asmap.h>
+#include <util/check.h>
#include <util/moneystr.h>
#include <util/string.h>
#include <util/system.h>
@@ -152,6 +153,8 @@ NODISCARD static bool CreatePidFile()
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
+static std::thread g_load_block;
+
static boost::thread_group threadGroup;
void Interrupt(NodeContext& node)
@@ -214,8 +217,9 @@ void Shutdown(NodeContext& node)
StopTorControl();
// After everything has been shut down, but before things get flushed, stop the
- // CScheduler/checkqueue threadGroup
+ // CScheduler/checkqueue, threadGroup and load block thread.
if (node.scheduler) node.scheduler->stop();
+ if (g_load_block.joinable()) g_load_block.join();
threadGroup.interrupt_all();
threadGroup.join_all();
@@ -680,7 +684,6 @@ static void CleanupBlockRevFiles()
static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles)
{
const CChainParams& chainparams = Params();
- util::ThreadRename("loadblk");
ScheduleBatchPriority();
{
@@ -1315,8 +1318,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
node.scheduler = MakeUnique<CScheduler>();
// Start the lightweight task scheduler thread
- CScheduler::Function serviceLoop = [&node]{ node.scheduler->serviceQueue(); };
- threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
+ threadGroup.create_thread([&] { TraceThread("scheduler", [&] { node.scheduler->serviceQueue(); }); });
// Gather some entropy once per minute.
node.scheduler->scheduleEvery([]{
@@ -1377,9 +1379,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
node.mempool = &::mempool;
assert(!node.chainman);
node.chainman = &g_chainman;
- ChainstateManager& chainman = EnsureChainman(node);
+ ChainstateManager& chainman = *Assert(node.chainman);
- node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, *node.chainman, *node.mempool));
+ node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, chainman, *node.mempool));
RegisterValidationInterface(node.peer_logic.get());
// sanitize comments per BIP-0014, format user agent and check total size
@@ -1587,7 +1589,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
- if (!::BlockIndex().empty() &&
+ if (!chainman.BlockIndex().empty() &&
!LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
}
@@ -1842,7 +1844,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
vImportFiles.push_back(strFile);
}
- threadGroup.create_thread([=, &chainman] { ThreadImport(chainman, vImportFiles); });
+ g_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman]{ ThreadImport(chainman, vImportFiles); });
// Wait for genesis block to be processed
{
@@ -1867,8 +1869,8 @@ bool AppInitMain(const util::Ref& context, NodeContext& node)
//// debug print
{
LOCK(cs_main);
- LogPrintf("block tree size = %u\n", ::BlockIndex().size());
- chain_active_height = ::ChainActive().Height();
+ LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
+ chain_active_height = chainman.ActiveChain().Height();
}
LogPrintf("nBestHeight = %d\n", chain_active_height);