Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | void Shutdown(NodeContext &node) { | ||||
LogPrintf("%s: In progress...\n", __func__); | LogPrintf("%s: In progress...\n", __func__); | ||||
Assert(node.args); | Assert(node.args); | ||||
/// Note: Shutdown() must be able to handle cases in which initialization | /// Note: Shutdown() must be able to handle cases in which initialization | ||||
/// failed part of the way, for example if the data directory was found to | /// failed part of the way, for example if the data directory was found to | ||||
/// be locked. Be sure that anything that writes files or flushes caches | /// be locked. Be sure that anything that writes files or flushes caches | ||||
/// only does this if the respective module was initialized. | /// only does this if the respective module was initialized. | ||||
util::ThreadRename("shutoff"); | util::ThreadRename("shutoff"); | ||||
g_mempool.AddTransactionsUpdated(1); | if (node.mempool) { | ||||
node.mempool->AddTransactionsUpdated(1); | |||||
} | |||||
StopHTTPRPC(); | StopHTTPRPC(); | ||||
StopREST(); | StopREST(); | ||||
StopRPC(); | StopRPC(); | ||||
StopHTTPServer(); | StopHTTPServer(); | ||||
for (const auto &client : node.chain_clients) { | for (const auto &client : node.chain_clients) { | ||||
client->flush(); | client->flush(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | void Shutdown(NodeContext &node) { | ||||
// stopped, destruct and reset all to nullptr. | // stopped, destruct and reset all to nullptr. | ||||
node.peerman.reset(); | node.peerman.reset(); | ||||
// Destroy various global instances | // Destroy various global instances | ||||
g_avalanche.reset(); | g_avalanche.reset(); | ||||
node.connman.reset(); | node.connman.reset(); | ||||
node.banman.reset(); | node.banman.reset(); | ||||
if (::g_mempool.IsLoaded() && | if (node.mempool && node.mempool->IsLoaded() && | ||||
node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | ||||
DumpMempool(::g_mempool); | DumpMempool(*node.mempool); | ||||
} | } | ||||
// FlushStateToDisk generates a ChainStateFlushed callback, which we should | // FlushStateToDisk generates a ChainStateFlushed callback, which we should | ||||
// avoid missing | // avoid missing | ||||
if (node.chainman) { | if (node.chainman) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
for (CChainState *chainstate : node.chainman->GetAll()) { | for (CChainState *chainstate : node.chainman->GetAll()) { | ||||
if (chainstate->CanFlushToDisk()) { | if (chainstate->CanFlushToDisk()) { | ||||
▲ Show 20 Lines • Show All 1,185 Lines • ▼ Show 20 Lines | ScheduleBatchPriority(); | ||||
if (args.GetBoolArg("-stopafterblockimport", | if (args.GetBoolArg("-stopafterblockimport", | ||||
DEFAULT_STOPAFTERBLOCKIMPORT)) { | DEFAULT_STOPAFTERBLOCKIMPORT)) { | ||||
LogPrintf("Stopping after block import\n"); | LogPrintf("Stopping after block import\n"); | ||||
StartShutdown(); | StartShutdown(); | ||||
return; | return; | ||||
} | } | ||||
} // End scope of CImportingNow | } // End scope of CImportingNow | ||||
if (args.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { | chainman.ActiveChainstate().LoadMempool(config, args); | ||||
LoadMempool(config, ::g_mempool); | |||||
} | |||||
::g_mempool.SetIsLoaded(!ShutdownRequested()); | |||||
} | } | ||||
/** Sanity checks | /** Sanity checks | ||||
* Ensure that Bitcoin is running in a usable environment with all | * Ensure that Bitcoin is running in a usable environment with all | ||||
* necessary library support. | * necessary library support. | ||||
*/ | */ | ||||
static bool InitSanityCheck() { | static bool InitSanityCheck() { | ||||
if (!ECC_InitSanityCheck()) { | if (!ECC_InitSanityCheck()) { | ||||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Lines | #endif | ||||
// Now remove the logging categories which were explicitly excluded | // Now remove the logging categories which were explicitly excluded | ||||
for (const std::string &cat : args.GetArgs("-debugexclude")) { | for (const std::string &cat : args.GetArgs("-debugexclude")) { | ||||
if (!LogInstance().DisableCategory(cat)) { | if (!LogInstance().DisableCategory(cat)) { | ||||
InitWarning(strprintf(_("Unsupported logging category %s=%s."), | InitWarning(strprintf(_("Unsupported logging category %s=%s."), | ||||
"-debugexclude", cat)); | "-debugexclude", cat)); | ||||
} | } | ||||
} | } | ||||
// Checkmempool and checkblockindex default to true in regtest mode | |||||
int ratio = std::min<int>( | |||||
std::max<int>( | |||||
args.GetArg("-checkmempool", | |||||
chainparams.DefaultConsistencyChecks() ? 1 : 0), | |||||
0), | |||||
1000000); | |||||
if (ratio != 0) { | |||||
g_mempool.setSanityCheck(1.0 / ratio); | |||||
} | |||||
fCheckBlockIndex = args.GetBoolArg("-checkblockindex", | fCheckBlockIndex = args.GetBoolArg("-checkblockindex", | ||||
chainparams.DefaultConsistencyChecks()); | chainparams.DefaultConsistencyChecks()); | ||||
fCheckpointsEnabled = | fCheckpointsEnabled = | ||||
args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED); | args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED); | ||||
if (fCheckpointsEnabled) { | if (fCheckpointsEnabled) { | ||||
LogPrintf("Checkpoints will be verified.\n"); | LogPrintf("Checkpoints will be verified.\n"); | ||||
} else { | } else { | ||||
LogPrintf("Skipping checkpoint verification.\n"); | LogPrintf("Skipping checkpoint verification.\n"); | ||||
▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | node.connman = std::make_unique<CConnman>( | ||||
GetRand(std::numeric_limits<uint64_t>::max()), | GetRand(std::numeric_limits<uint64_t>::max()), | ||||
gArgs.GetBoolArg("-networkactive", true)); | gArgs.GetBoolArg("-networkactive", true)); | ||||
// Make mempool generally available in the node context. For example the | // Make mempool generally available in the node context. For example the | ||||
// connection manager, wallet, or RPC threads, which are all started after | // connection manager, wallet, or RPC threads, which are all started after | ||||
// this, may use it from the node context. | // this, may use it from the node context. | ||||
assert(!node.mempool); | assert(!node.mempool); | ||||
node.mempool = &::g_mempool; | node.mempool = &::g_mempool; | ||||
if (node.mempool) { | |||||
int ratio = std::min<int>( | |||||
std::max<int>( | |||||
args.GetArg("-checkmempool", | |||||
chainparams.DefaultConsistencyChecks() ? 1 : 0), | |||||
0), | |||||
1000000); | |||||
if (ratio != 0) { | |||||
node.mempool->setSanityCheck(1.0 / ratio); | |||||
} | |||||
} | |||||
assert(!node.chainman); | assert(!node.chainman); | ||||
node.chainman = &g_chainman; | node.chainman = &g_chainman; | ||||
ChainstateManager &chainman = *Assert(node.chainman); | ChainstateManager &chainman = *Assert(node.chainman); | ||||
node.peerman.reset(new PeerManager(chainparams, *node.connman, | node.peerman.reset(new PeerManager(chainparams, *node.connman, | ||||
node.banman.get(), *node.scheduler, | node.banman.get(), *node.scheduler, | ||||
chainman, *node.mempool)); | chainman, *node.mempool)); | ||||
▲ Show 20 Lines • Show All 722 Lines • Show Last 20 Lines |