From a67b54855b294802d52f09fa60d3f63550cbada7 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Sun, 18 Apr 2021 18:56:12 -0400 Subject: [PATCH] Move common global init code to init/common --- src/Makefile.am | 2 ++ src/init.cpp | 14 +++----------- src/init/common.cpp | 30 ++++++++++++++++++++++++++++++ src/init/common.h | 16 ++++++++++++++++ 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 src/init/common.cpp create mode 100644 src/init/common.h diff --git a/src/Makefile.am b/src/Makefile.am index ddeccd85ea9..d2f643c03a9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -156,6 +156,7 @@ BITCOIN_CORE_H = \ index/txindex.h \ indirectmap.h \ init.h \ + init/common.h \ interfaces/chain.h \ interfaces/handler.h \ interfaces/node.h \ @@ -520,6 +521,7 @@ libbitcoin_common_a_SOURCES = \ core_read.cpp \ core_write.cpp \ external_signer.cpp \ + init/common.cpp \ key.cpp \ key_io.cpp \ merkleblock.cpp \ diff --git a/src/init.cpp b/src/init.cpp index 07e882c9df2..4298494916b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -22,9 +22,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -151,8 +151,6 @@ static fs::path GetPidFile(const ArgsManager& args) // shutdown thing. // -static std::unique_ptr globalVerifyHandle; - void Interrupt(NodeContext& node) { InterruptHTTPServer(); @@ -286,8 +284,7 @@ void Shutdown(NodeContext& node) node.chain_clients.clear(); UnregisterAllValidationInterfaces(); GetMainSignals().UnregisterBackgroundSignalScheduler(); - globalVerifyHandle.reset(); - ECC_Stop(); + init::UnsetGlobals(); node.mempool.reset(); node.fee_estimator.reset(); node.chainman = nullptr; @@ -1148,12 +1145,7 @@ bool AppInitSanityChecks() { // ********************************************************* Step 4: sanity checks - // Initialize elliptic curve code - std::string sha256_algo = SHA256AutoDetect(); - LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo); - RandomInit(); - ECC_Start(); - globalVerifyHandle.reset(new ECCVerifyHandle()); + init::SetGlobals(); // Sanity check if (!InitSanityCheck()) diff --git a/src/init/common.cpp b/src/init/common.cpp new file mode 100644 index 00000000000..cb247080317 --- /dev/null +++ b/src/init/common.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2021 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 +#include +#include +#include +#include + +#include + +static std::unique_ptr globalVerifyHandle; + +namespace init { +void SetGlobals() +{ + std::string sha256_algo = SHA256AutoDetect(); + LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo); + RandomInit(); + ECC_Start(); + globalVerifyHandle.reset(new ECCVerifyHandle()); +} + +void UnsetGlobals() +{ + globalVerifyHandle.reset(); + ECC_Stop(); +} +} // namespace init diff --git a/src/init/common.h b/src/init/common.h new file mode 100644 index 00000000000..b201232bfc3 --- /dev/null +++ b/src/init/common.h @@ -0,0 +1,16 @@ +// Copyright (c) 2021 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +//! @file +//! @brief Common init functions shared by bitcoin-node, bitcoin-wallet, etc. + +#ifndef BITCOIN_INIT_COMMON_H +#define BITCOIN_INIT_COMMON_H + +namespace init { +void SetGlobals(); +void UnsetGlobals(); +} // namespace init + +#endif // BITCOIN_INIT_COMMON_H