0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

Move common global init code to init/common

This commit is contained in:
Russell Yanofsky 2021-04-18 18:56:12 -04:00
parent 13d27b452d
commit a67b54855b
4 changed files with 51 additions and 11 deletions

View file

@ -156,6 +156,7 @@ BITCOIN_CORE_H = \
index/txindex.h \ index/txindex.h \
indirectmap.h \ indirectmap.h \
init.h \ init.h \
init/common.h \
interfaces/chain.h \ interfaces/chain.h \
interfaces/handler.h \ interfaces/handler.h \
interfaces/node.h \ interfaces/node.h \
@ -520,6 +521,7 @@ libbitcoin_common_a_SOURCES = \
core_read.cpp \ core_read.cpp \
core_write.cpp \ core_write.cpp \
external_signer.cpp \ external_signer.cpp \
init/common.cpp \
key.cpp \ key.cpp \
key_io.cpp \ key_io.cpp \
merkleblock.cpp \ merkleblock.cpp \

View file

@ -22,9 +22,9 @@
#include <httpserver.h> #include <httpserver.h>
#include <index/blockfilterindex.h> #include <index/blockfilterindex.h>
#include <index/txindex.h> #include <index/txindex.h>
#include <init/common.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <interfaces/node.h> #include <interfaces/node.h>
#include <key.h>
#include <mapport.h> #include <mapport.h>
#include <miner.h> #include <miner.h>
#include <net.h> #include <net.h>
@ -151,8 +151,6 @@ static fs::path GetPidFile(const ArgsManager& args)
// shutdown thing. // shutdown thing.
// //
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
void Interrupt(NodeContext& node) void Interrupt(NodeContext& node)
{ {
InterruptHTTPServer(); InterruptHTTPServer();
@ -286,8 +284,7 @@ void Shutdown(NodeContext& node)
node.chain_clients.clear(); node.chain_clients.clear();
UnregisterAllValidationInterfaces(); UnregisterAllValidationInterfaces();
GetMainSignals().UnregisterBackgroundSignalScheduler(); GetMainSignals().UnregisterBackgroundSignalScheduler();
globalVerifyHandle.reset(); init::UnsetGlobals();
ECC_Stop();
node.mempool.reset(); node.mempool.reset();
node.fee_estimator.reset(); node.fee_estimator.reset();
node.chainman = nullptr; node.chainman = nullptr;
@ -1148,12 +1145,7 @@ bool AppInitSanityChecks()
{ {
// ********************************************************* Step 4: sanity checks // ********************************************************* Step 4: sanity checks
// Initialize elliptic curve code init::SetGlobals();
std::string sha256_algo = SHA256AutoDetect();
LogPrintf("Using the '%s' SHA256 implementation\n", sha256_algo);
RandomInit();
ECC_Start();
globalVerifyHandle.reset(new ECCVerifyHandle());
// Sanity check // Sanity check
if (!InitSanityCheck()) if (!InitSanityCheck())

30
src/init/common.cpp Normal file
View file

@ -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 <crypto/sha256.h>
#include <key.h>
#include <logging.h>
#include <pubkey.h>
#include <random.h>
#include <memory>
static std::unique_ptr<ECCVerifyHandle> 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

16
src/init/common.h Normal file
View file

@ -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