diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -353,6 +353,7 @@ consensus/params.h \ consensus/validation.h \ feerate.h \ + globals.cpp \ hash.cpp \ hash.h \ prevector.h \ @@ -423,6 +424,7 @@ compat/glibcxx_sanity.cpp \ compat/strnlen.cpp \ fs.cpp \ + globals.cpp \ logging.cpp \ random.cpp \ rpc/protocol.cpp \ diff --git a/src/globals.h b/src/globals.h --- a/src/globals.h +++ b/src/globals.h @@ -7,5 +7,36 @@ #include #include +#include + +namespace BCLog { +class Logger; +} +class CTxMemPool; +class CChain; +class CBlockIndex; +class uint256; +struct BlockHasher; + +typedef std::unordered_map BlockMap; + +extern CTxMemPool g_mempool; +extern BlockMap mapBlockIndex; +extern CChain chainActive; + +/** + * NOTE: the logger instance is leaked on exit. This is ugly, but will be + * cleaned up by the OS/libc. Defining a logger as a global object doesn't work + * since the order of destruction of static/global objects is undefined. + * Consider if the logger gets destroyed, and then some later destructor calls + * LogPrintf, maybe indirectly, and you get a core dump at shutdown trying to + * access the logger. When the shutdown sequence is fully audited and tested, + * explicit destruction of these objects can be implemented by changing this + * from a raw pointer to a std::unique_ptr. + * + * This method of initialization was originally introduced in + * ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c. + */ +extern BCLog::Logger *const logger; #endif // BITCOIN_GLOBALS_H diff --git a/src/globals.cpp b/src/globals.cpp --- a/src/globals.cpp +++ b/src/globals.cpp @@ -4,5 +4,14 @@ #include "globals.h" +#include "chain.h" #include "consensus/consensus.h" +#include "logging.h" #include "policy/policy.h" +#include "txmempool.h" +#include "uint256.h" + +CTxMemPool g_mempool; +BlockMap mapBlockIndex; +CChain chainActive; +BCLog::Logger *const logger = new BCLog::Logger(); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -19,6 +19,7 @@ #include "consensus/validation.h" #include "diskblockpos.h" #include "fs.h" +#include "globals.h" #include "httprpc.h" #include "httpserver.h" #include "key.h" diff --git a/src/logging.cpp b/src/logging.cpp --- a/src/logging.cpp +++ b/src/logging.cpp @@ -5,26 +5,13 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "logging.h" +#include "globals.h" #include "util.h" #include "utiltime.h" bool fLogIPs = DEFAULT_LOGIPS; -/** - * NOTE: the logger instance is leaked on exit. This is ugly, but will be - * cleaned up by the OS/libc. Defining a logger as a global object doesn't work - * since the order of destruction of static/global objects is undefined. - * Consider if the logger gets destroyed, and then some later destructor calls - * LogPrintf, maybe indirectly, and you get a core dump at shutdown trying to - * access the logger. When the shutdown sequence is fully audited and tested, - * explicit destruction of these objects can be implemented by changing this - * from a raw pointer to a std::unique_ptr. - * - * This method of initialization was originally introduced in - * ee3374234c60aba2cc4c5cd5cac1c0aefc2d817c. - */ BCLog::Logger &GetLogger() { - static BCLog::Logger *const logger = new BCLog::Logger(); return *logger; } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -12,6 +12,7 @@ #include "chainparams.h" #include "config.h" #include "consensus/validation.h" +#include "globals.h" #include "hash.h" #include "init.h" #include "merkleblock.h" diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1136,9 +1136,7 @@ void BitcoinGUI::detectShutdown() { if (ShutdownRequested()) { - if (rpcConsole) { - rpcConsole->hide(); - } + if (rpcConsole) rpcConsole->hide(); qApp->quit(); } } @@ -1151,12 +1149,13 @@ progressDialog->setCancelButton(0); progressDialog->setAutoClose(false); progressDialog->setValue(0); - } else if (nProgress == 100 && progressDialog) { - progressDialog->close(); - progressDialog->deleteLater(); - } else if (progressDialog) { + } else if (nProgress == 100) { + if (progressDialog) { + progressDialog->close(); + progressDialog->deleteLater(); + } + } else if (progressDialog) progressDialog->setValue(nProgress); - } } void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon) { @@ -1167,9 +1166,8 @@ void BitcoinGUI::showModalOverlay() { if (modalOverlay && - (progressBar->isVisible() || modalOverlay->isLayerVisible())) { + (progressBar->isVisible() || modalOverlay->isLayerVisible())) modalOverlay->toggleVisibility(); - } } static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string &message, diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -13,6 +13,7 @@ #include "checkpoints.h" #include "clientversion.h" #include "config.h" +#include "globals.h" #include "net.h" #include "txmempool.h" #include "ui_interface.h" diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -14,6 +14,7 @@ #include "walletmodel.h" #include "dstencode.h" +#include "globals.h" #include "init.h" #include "policy/policy.h" #include "validation.h" // For mempool diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -17,6 +17,7 @@ #include "chainparams.h" #include "dstencode.h" +#include "globals.h" #include "txmempool.h" #include "ui_interface.h" #include "validation.h" // mempool and minRelayTxFee diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -6,6 +6,7 @@ #include "chain.h" #include "chainparams.h" #include "config.h" +#include "globals.h" #include "httpserver.h" #include "primitives/block.h" #include "primitives/transaction.h" diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -12,6 +12,7 @@ #include "coins.h" #include "config.h" #include "consensus/validation.h" +#include "globals.h" #include "hash.h" #include "policy/policy.h" #include "primitives/transaction.h" diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -14,6 +14,7 @@ #include "consensus/validation.h" #include "core_io.h" #include "dstencode.h" +#include "globals.h" #include "init.h" #include "miner.h" #include "net.h" diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -10,6 +10,7 @@ #include "consensus/validation.h" #include "core_io.h" #include "dstencode.h" +#include "globals.h" #include "init.h" #include "keystore.h" #include "merkleblock.h" diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -12,6 +12,7 @@ #include "consensus/merkle.h" #include "consensus/tx_verify.h" #include "consensus/validation.h" +#include "globals.h" #include "policy/policy.h" #include "pubkey.h" #include "script/standard.h" diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -10,6 +10,7 @@ #include "consensus/validation.h" #include "crypto/sha256.h" #include "fs.h" +#include "globals.h" #include "key.h" #include "logging.h" #include "miner.h" diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp --- a/src/test/txvalidationcache_tests.cpp +++ b/src/test/txvalidationcache_tests.cpp @@ -4,6 +4,7 @@ #include "config.h" #include "consensus/validation.h" +#include "globals.h" #include "key.h" #include "keystore.h" #include "miner.h" diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -10,6 +10,7 @@ #include "consensus/consensus.h" #include "consensus/tx_verify.h" #include "consensus/validation.h" +#include "globals.h" #include "policy/fees.h" #include "policy/policy.h" #include "streams.h" diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -198,7 +198,6 @@ extern CScript COINBASE_FLAGS; extern CCriticalSection cs_main; -extern CTxMemPool g_mempool; extern uint64_t nLastBlockTx; extern uint64_t nLastBlockSize; extern const std::string strMessageMagic; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -19,6 +19,7 @@ #include "consensus/tx_verify.h" #include "consensus/validation.h" #include "fs.h" +#include "globals.h" #include "hash.h" #include "init.h" #include "policy/fees.h" @@ -61,8 +62,6 @@ */ CCriticalSection cs_main; -BlockMap mapBlockIndex; -CChain chainActive; CBlockIndex *pindexBestHeader = nullptr; CWaitableCriticalSection g_best_block_mutex; CConditionVariable g_best_block_cv; @@ -86,8 +85,6 @@ Amount maxTxFee = DEFAULT_TRANSACTION_MAXFEE; -CTxMemPool g_mempool; - static void CheckBlockIndex(const Consensus::Params &consensusParams); /** Constant stuff for coinbase transactions we create: */ diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -12,6 +12,7 @@ #include "consensus/validation.h" #include "dstencode.h" #include "fs.h" +#include "globals.h" #include "init.h" #include "key.h" #include "keystore.h"