MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Shutdown

Function Shutdown

src/init.cpp:311–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309}
310
311void Shutdown(NodeContext& node)
312{
313 static Mutex g_shutdown_mutex;
314 TRY_LOCK(g_shutdown_mutex, lock_shutdown);
315 if (!lock_shutdown) return;
316 LogInfo("Shutdown in progress...");
317 Assert(node.args);
318
319 /// Note: Shutdown() must be able to handle cases in which initialization failed part of the way,
320 /// for example if the data directory was found to be locked.
321 /// Be sure that anything that writes files or flushes caches only does this if the respective
322 /// module was initialized.
323 util::ThreadRename("shutoff");
324 if (node.mempool) node.mempool->AddTransactionsUpdated(1);
325
326 StopHTTPRPC();
327 StopREST();
328 StopRPC();
329 StopHTTPServer();
330 for (auto& client : node.chain_clients) {
331 try {
332 client->stop();
333 } catch (const ipc::Exception& e) {
334 LogDebug(BCLog::IPC, "Chain client did not disconnect cleanly: %s", e.what());
335 client.reset();
336 }
337 }
338 StopMapPort();
339
340 // Because these depend on each-other, we make sure that neither can be
341 // using the other before destroying them.
342 if (node.peerman && node.validation_signals) node.validation_signals->UnregisterValidationInterface(node.peerman.get());
343 if (node.connman) node.connman->Stop();
344
345 if (node.tor_controller) {
346 node.tor_controller->Join();
347 node.tor_controller.reset();
348 }
349
350 if (node.background_init_thread.joinable()) node.background_init_thread.join();
351 // After everything has been shut down, but before things get flushed, stop the
352 // the scheduler. After this point, SyncWithValidationInterfaceQueue() should not be called anymore
353 // as this would prevent the shutdown from completing.
354 if (node.scheduler) node.scheduler->stop();
355
356 // After the threads that potentially access these pointers have been stopped,
357 // destruct and reset all to nullptr.
358 node.peerman.reset();
359 node.connman.reset();
360 node.banman.reset();
361 node.addrman.reset();
362 node.netgroupman.reset();
363
364 if (node.mempool && node.mempool->GetLoadTried() && ShouldPersistMempool(*node.args)) {
365 DumpMempool(*node.mempool, MempoolPath(*node.args));
366 }
367
368 // Drop transactions we were still watching, record fee estimations and unregister

Callers 4

bitcoind.cppFile · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
appShutdownMethod · 0.85

Calls 15

StopHTTPRPCFunction · 0.85
StopRESTFunction · 0.85
StopRPCFunction · 0.85
StopHTTPServerFunction · 0.85
StopMapPortFunction · 0.85
ShouldPersistMempoolFunction · 0.85
DumpMempoolFunction · 0.85
MempoolPathFunction · 0.85
RemovePidFileFunction · 0.85

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68