Merge #13235: Break circular dependency: init -> * -> init by extracting shutdown.h

1fabd59e7 Break circular dependency: init -> * -> init by extracting shutdown.h (Ben Woosley)
e62fdfeea Drop unused init.h includes (Ben Woosley)

Pull request description:

  Most includers just wanted to react to pending shutdown.

  This isolates access to `fRequestShutdown` and limits access to the shutdown api functions, including the new `CancelShutdown` for setting it to `false`.

Tree-SHA512: df42f75dfbba163576710e9a67cf1228531fd99d70a2f187bfba0bcc476d6749cf88180a97e66a81bb5b6c3c7f0917de7402d26039ba7b644cb7509b02f7e267
This commit is contained in:
Wladimir J. van der Laan 2021-06-21 01:49:59 +03:00 committed by UdjinM6
parent d25d155ff7
commit 4cd32e43e4
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
35 changed files with 90 additions and 90 deletions

View File

@ -241,6 +241,7 @@ BITCOIN_CORE_H = \
script/sigcache.h \
script/sign.h \
script/standard.h \
shutdown.h \
spork.h \
stacktraces.h \
streams.h \
@ -382,6 +383,7 @@ libdash_server_a_SOURCES = \
rpc/coinjoin.cpp \
rpc/util.cpp \
script/sigcache.cpp \
shutdown.cpp \
spork.cpp \
statsd_client.cpp \
timedata.cpp \

View File

@ -7,13 +7,13 @@
#include <consensus/validation.h>
#include <core_io.h>
#include <init.h>
#include <evo/deterministicmns.h>
#include <masternode/masternode-sync.h>
#include <masternode/masternode-meta.h>
#include <netmessagemaker.h>
#include <net_processing.h>
#include <script/sign.h>
#include <shutdown.h>
#include <txmempool.h>
#include <util/system.h>
#include <util/moneystr.h>

View File

@ -8,12 +8,12 @@
#include <evo/deterministicmns.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <init.h>
#include <masternode/masternode-meta.h>
#include <masternode/masternode-sync.h>
#include <net_processing.h>
#include <netmessagemaker.h>
#include <script/interpreter.h>
#include <shutdown.h>
#include <txmempool.h>
#include <util/system.h>
#include <util/moneystr.h>

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -15,6 +15,7 @@
#include <rpc/server.h>
#include <init.h>
#include <noui.h>
#include <shutdown.h>
#include <util/system.h>
#include <httpserver.h>
#include <httprpc.h>

View File

@ -9,13 +9,13 @@
#include <consensus/validation.h>
#include <governance/governance-classes.h>
#include <governance/governance-validators.h>
#include <init.h>
#include <masternode/masternode-meta.h>
#include <masternode/masternode-sync.h>
#include <net_processing.h>
#include <netfulfilledman.h>
#include <netmessagemaker.h>
#include <protocol.h>
#include <shutdown.h>
#include <spork.h>
#include <evo/deterministicmns.h>

View File

@ -4,7 +4,6 @@
#include <httpserver.h>
#include <init.h>
#include <chainparamsbase.h>
#include <compat.h>
#include <util/system.h>
@ -12,6 +11,7 @@
#include <util/threadnames.h>
#include <netbase.h>
#include <rpc/protocol.h> // For HTTP status codes
#include <shutdown.h>
#include <sync.h>
#include <ui_interface.h>

View File

@ -4,7 +4,7 @@
#include <chainparams.h>
#include <index/base.h>
#include <init.h>
#include <shutdown.h>
#include <tinyformat.h>
#include <ui_interface.h>
#include <validation.h>

View File

@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <index/txindex.h>
#include <init.h>
#include <shutdown.h>
#include <ui_interface.h>
#include <util/system.h>
#include <validation.h>

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -39,7 +39,7 @@
#include <script/standard.h>
#include <script/sigcache.h>
#include <scheduler.h>
#include <util/threadnames.h>
#include <shutdown.h>
#include <timedata.h>
#include <txdb.h>
#include <txmempool.h>
@ -49,6 +49,7 @@
#include <util/error.h>
#include <util/moneystr.h>
#include <util/system.h>
#include <util/threadnames.h>
#include <util/validation.h>
#include <validationinterface.h>
@ -172,7 +173,7 @@ static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
// created by AppInit() or the Qt main() function.
//
// A clean exit happens when StartShutdown() or the SIGTERM
// signal handler sets fRequestShutdown, which makes main thread's
// signal handler sets ShutdownRequested(), which makes main thread's
// WaitForShutdown() interrupts the thread group.
// And then, WaitForShutdown() makes all other on-going threads
// in the thread group join the main thread.
@ -181,26 +182,10 @@ static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
// threads have exited.
//
// Shutdown for Qt is very similar, only it uses a QTimer to detect
// fRequestShutdown getting set, and then does the normal Qt
// ShutdownRequested() getting set, and then does the normal Qt
// shutdown thing.
//
std::atomic<bool> fRequestShutdown(false);
std::atomic<bool> fRequestRestart(false);
void StartShutdown()
{
fRequestShutdown = true;
}
void StartRestart()
{
fRequestShutdown = fRequestRestart = true;
}
bool ShutdownRequested()
{
return fRequestShutdown;
}
/**
* This is a minimally invasive approach to shutdown on LevelDB read errors from the
* chainstate, while keeping user interface out of the common library, which is shared
@ -406,7 +391,7 @@ void PrepareShutdown()
void Shutdown()
{
// Shutdown part 1: prepare shutdown
if(!fRequestRestart) {
if(!RestartRequested()) {
PrepareShutdown();
}
// Shutdown part 2: delete wallet instance
@ -424,7 +409,7 @@ void Shutdown()
#ifndef WIN32
static void HandleSIGTERM(int)
{
fRequestShutdown = true;
StartShutdown();
}
static void HandleSIGHUP(int)
@ -434,7 +419,7 @@ static void HandleSIGHUP(int)
#else
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
{
fRequestShutdown = true;
StartShutdown();
Sleep(INFINITE);
return true;
}
@ -943,7 +928,7 @@ static void ThreadImport(std::vector<fs::path> vImportFiles)
if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
LoadMempool();
}
g_is_mempool_loaded = !fRequestShutdown;
g_is_mempool_loaded = !ShutdownRequested();
}
void PeriodicStats()
@ -2053,7 +2038,7 @@ bool AppInitMain()
bool fLoaded = false;
int64_t nStart = GetTimeMillis();
while (!fLoaded && !fRequestShutdown) {
while (!fLoaded && !ShutdownRequested()) {
bool fReset = fReindex;
std::string strLoadError;
@ -2088,7 +2073,7 @@ bool AppInitMain()
CleanupBlockRevFiles();
}
if (fRequestShutdown) break;
if (ShutdownRequested()) break;
// LoadBlockIndex will load fHavePruned if we've ever removed a
// block file from disk.
@ -2230,7 +2215,7 @@ bool AppInitMain()
LogPrintf(" block index %15dms\n", GetTimeMillis() - load_block_index_start_time);
} while(false);
if (!fLoaded && !fRequestShutdown) {
if (!fLoaded && !ShutdownRequested()) {
// first suggest a reindex
if (!fReset) {
bool fRet = uiInterface.ThreadSafeQuestion(
@ -2239,7 +2224,7 @@ bool AppInitMain()
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;
fRequestShutdown = false;
AbortShutdown();
} else {
LogPrintf("Aborted block database rebuild. Exiting.\n");
return false;
@ -2253,8 +2238,7 @@ bool AppInitMain()
// As LoadBlockIndex can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
// As the program has not fully started yet, Shutdown() is possibly overkill.
if (fRequestShutdown)
{
if (ShutdownRequested()) {
LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
@ -2277,7 +2261,7 @@ bool AppInitMain()
// As InitLoadWallet can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
if (fRequestShutdown)
if (ShutdownRequested())
{
LogPrintf("Shutdown requested. Exiting.\n");
return false;
@ -2298,7 +2282,7 @@ bool AppInitMain()
// As PruneAndFlush can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit.
if (fRequestShutdown)
if (ShutdownRequested())
{
LogPrintf("Shutdown requested. Exiting.\n");
return false;

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -21,9 +21,6 @@ namespace boost
class thread_group;
} // namespace boost
void StartShutdown();
void StartRestart();
bool ShutdownRequested();
/** Interrupt threads */
void Interrupt();
void Shutdown();

View File

@ -24,6 +24,7 @@
#include <primitives/block.h>
#include <rpc/server.h>
#include <scheduler.h>
#include <shutdown.h>
#include <sync.h>
#include <txmempool.h>
#include <ui_interface.h>

View File

@ -12,7 +12,6 @@
#include <evo/deterministicmns.h>
#include <masternode/activemasternode.h>
#include <bls/bls_batchverifier.h>
#include <init.h>
#include <net_processing.h>
#include <netmessagemaker.h>
#include <spork.h>

View File

@ -3,11 +3,11 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <governance/governance.h>
#include <init.h>
#include <validation.h>
#include <masternode/masternode-sync.h>
#include <netfulfilledman.h>
#include <netmessagemaker.h>
#include <shutdown.h>
#include <ui_interface.h>
#include <evo/deterministicmns.h>

View File

@ -8,9 +8,9 @@
#ifdef ENABLE_WALLET
#include <coinjoin/coinjoin-client.h>
#endif
#include <init.h>
#include <masternode/masternode-sync.h>
#include <net.h>
#include <shutdown.h>
#include <validation.h>

View File

@ -11,7 +11,6 @@
#include <chainparams.h>
#include <consensus/validation.h>
#include <hash.h>
#include <init.h>
#include <merkleblock.h>
#include <netmessagemaker.h>
#include <netbase.h>

View File

@ -3,8 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <init.h>
#include <netfulfilledman.h>
#include <shutdown.h>
#include <util/system.h>
CNetFulfilledRequestManager netfulfilledman;

View File

@ -29,7 +29,6 @@
#endif
#include <chainparams.h>
#include <init.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <ui_interface.h>

View File

@ -335,7 +335,7 @@ private Q_SLOTS:
/** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
void toggleHidden();
/** called by a timer to check if fRequestShutdown has been set **/
/** called by a timer to check if ShutdownRequested() has been set **/
void detectShutdown();
/** Show progress dialog e.g. for verifychain */

View File

@ -27,7 +27,6 @@
#include <qt/walletmodel.h>
#endif
#include <init.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <rpc/server.h>

View File

@ -10,7 +10,6 @@
#include <qt/guiutil.h>
#include <qt/walletmodel.h>
#include <init.h>
#include <key_io.h>
#include <util/strencodings.h>
#include <util/validation.h> // For strMessageMagic

View File

@ -14,7 +14,6 @@
#include <chainparams.h>
#include <clientversion.h>
#include <init.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>

View File

@ -5,7 +5,7 @@
#include <qt/winshutdownmonitor.h>
#if defined(Q_OS_WIN)
#include <init.h>
#include <shutdown.h>
#include <util/system.h>
#include <windows.h>

View File

@ -1,5 +1,5 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -11,7 +11,6 @@
#include <consensus/params.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <init.h>
#include <key_io.h>
#include <miner.h>
#include <net.h>
@ -20,6 +19,7 @@
#include <rpc/blockchain.h>
#include <rpc/mining.h>
#include <rpc/server.h>
#include <shutdown.h>
#include <txmempool.h>
#include <util/fees.h>
#include <util/strencodings.h>

View File

@ -9,7 +9,6 @@
#include <consensus/consensus.h>
#include <core_io.h>
#include <evo/mnauth.h>
#include <init.h>
#include <httpserver.h>
#include <key_io.h>
#include <net.h>

View File

@ -9,7 +9,6 @@
#include <consensus/validation.h>
#include <core_io.h>
#include <index/txindex.h>
#include <init.h>
#include <keystore.h>
#include <validation.h>
#include <validationinterface.h>

View File

@ -6,7 +6,6 @@
#include <consensus/validation.h>
#include <core_io.h>
#include <index/txindex.h>
#include <init.h>
#include <messagesigner.h>
#include <rpc/server.h>
#include <txmempool.h>

View File

@ -1,5 +1,5 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -7,9 +7,9 @@
#include <rpc/server.h>
#include <fs.h>
#include <init.h>
#include <key_io.h>
#include <random.h>
#include <shutdown.h>
#include <sync.h>
#include <ui_interface.h>
#include <util/system.h>

32
src/shutdown.cpp Normal file
View File

@ -0,0 +1,32 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <shutdown.h>
#include <atomic>
static std::atomic<bool> fRequestShutdown(false);
static std::atomic<bool> fRequestRestart(false);
void StartShutdown()
{
fRequestShutdown = true;
}
void StartRestart()
{
fRequestShutdown = fRequestRestart = true;
}
void AbortShutdown()
{
fRequestShutdown = false;
}
bool ShutdownRequested()
{
return fRequestShutdown;
}
bool RestartRequested()
{
return fRequestRestart;
}

15
src/shutdown.h Normal file
View File

@ -0,0 +1,15 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_SHUTDOWN_H
#define BITCOIN_SHUTDOWN_H
void StartShutdown();
void StartRestart();
void AbortShutdown();
bool ShutdownRequested();
bool RestartRequested();
#endif

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -9,10 +9,10 @@
#include <hash.h>
#include <random.h>
#include <pow.h>
#include <shutdown.h>
#include <uint256.h>
#include <util/system.h>
#include <ui_interface.h>
#include <init.h>
#include <util/vector.h>
#include <stdint.h>

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -18,7 +18,6 @@
#include <cuckoocache.h>
#include <hash.h>
#include <index/txindex.h>
#include <init.h>
#include <logging.h>
#include <logging/timer.h>
#include <policy/fees.h>
@ -30,6 +29,7 @@
#include <script/script.h>
#include <script/sigcache.h>
#include <script/standard.h>
#include <shutdown.h>
#include <timedata.h>
#include <tinyformat.h>
#include <txdb.h>

View File

@ -5,7 +5,6 @@
#include <validationinterface.h>
#include <init.h>
#include <primitives/block.h>
#include <scheduler.h>
#include <sync.h>

View File

@ -1,5 +1,5 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Copyright (c) 2014-2021 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -32,8 +32,6 @@
#include <wallet/walletutil.h>
#include <key_io.h>
#include <init.h> // For StartShutdown
#include <coinjoin/coinjoin-client.h>
#include <coinjoin/coinjoin-client-options.h>
#include <llmq/quorums_chainlocks.h>

View File

@ -12,7 +12,6 @@
#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <fs.h>
#include <init.h>
#include <key.h>
#include <key_io.h>
#include <keystore.h>
@ -24,6 +23,7 @@
#include <primitives/transaction.h>
#include <script/script.h>
#include <script/sign.h>
#include <shutdown.h>
#include <timedata.h>
#include <txmempool.h>
#include <util/error.h>

View File

@ -37,10 +37,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/signverifymessagedialog -> qt/addressbookpage"
"qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/sendcoinsdialog -> qt/sendcoinsentry -> qt/addressbookpage"
# Dash
"coinjoin/coinjoin-server -> init -> coinjoin/coinjoin-server"
"coinjoin/coinjoin-server -> net_processing -> coinjoin/coinjoin-server"
"coinjoin/coinjoin-client -> init -> dsnotificationinterface -> coinjoin/coinjoin-client"
"coinjoin/coinjoin-client -> init -> masternode/masternode-utils -> coinjoin/coinjoin-client"
"evo/cbtx -> evo/simplifiedmns -> evo/cbtx"
"evo/cbtx -> evo/specialtx -> evo/cbtx"
"evo/deterministicmns -> evo/providertx -> evo/deterministicmns"
@ -55,18 +52,9 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"evo/specialtx -> validation -> evo/specialtx"
"governance/governance -> governance/governance-classes -> governance/governance"
"governance/governance -> governance/governance-object -> governance/governance"
"governance/governance -> init -> governance/governance"
"governance/governance -> masternode/masternode-sync -> governance/governance"
"governance/governance -> net_processing -> governance/governance"
"governance/governance-object -> governance/governance-validators -> governance/governance-object"
"init -> masternode/masternode-sync -> init"
"init -> masternode/masternode-utils -> init"
"init -> net_processing -> init"
"init -> netfulfilledman -> init"
"init -> rpc/server -> init"
"init -> txdb -> init"
"init -> validation -> init"
"init -> validationinterface -> init"
"llmq/quorums -> llmq/quorums_utils -> llmq/quorums"
"llmq/quorums_blockprocessor -> net_processing -> llmq/quorums_blockprocessor"
"llmq/quorums_chainlocks -> llmq/quorums_instantsend -> llmq/quorums_chainlocks"
@ -90,11 +78,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"qt/guiutil -> qt/qvalidatedlineedit -> qt/guiutil"
"core_io -> evo/cbtx -> evo/deterministicmns -> core_io"
"core_io -> evo/cbtx -> evo/simplifiedmns -> core_io"
"dsnotificationinterface -> governance/governance -> init -> dsnotificationinterface"
"evo/simplifiedmns -> llmq/quorums_blockprocessor -> net_processing -> evo/simplifiedmns"
"httprpc -> httpserver -> init -> httprpc"
"httpserver -> init -> httpserver"
"init -> llmq/quorums_init -> llmq/quorums_signing_shares -> init"
"llmq/quorums_dkgsession -> llmq/quorums_dkgsessionmgr -> llmq/quorums_dkgsessionhandler -> llmq/quorums_dkgsession"
"logging -> util/system -> random -> logging"
"logging -> util/system -> sync -> logging"
@ -127,10 +111,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"evo/deterministicmns -> evo/simplifiedmns -> llmq/quorums_blockprocessor -> net_processing -> masternode/masternode-payments -> governance/governance-classes -> governance/governance-object -> evo/deterministicmns"
"evo/deterministicmns -> evo/simplifiedmns -> llmq/quorums_blockprocessor -> net -> evo/deterministicmns"
"evo/deterministicmns -> evo/simplifiedmns -> llmq/quorums_blockprocessor -> net_processing -> masternode/masternode-payments -> governance/governance-classes -> governance/governance-object -> governance/governance-vote -> evo/deterministicmns"
"index/txindex -> init -> index/txindex"
"index/txindex -> init -> llmq/quorums_init -> llmq/quorums_instantsend -> index/txindex"
"index/txindex -> init -> net_processing -> index/txindex"
"index/txindex -> init -> rpc/blockchain -> index/txindex"
)
EXIT_CODE=0