diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -37,8 +38,11 @@ // (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) static void CoinSelection(benchmark::State &state) { SelectParams(CBaseChainParams::REGTEST); - const CWallet wallet(Params(), WalletLocation(), + + auto chain = interfaces::MakeChain(); + const CWallet wallet(Params(), *chain, WalletLocation(), WalletDatabase::CreateDummy()); + LOCK(wallet.cs_wallet); // Add coins. @@ -98,8 +102,11 @@ static void BnBExhaustion(benchmark::State &state) { SelectParams(CBaseChainParams::REGTEST); - const CWallet wallet(Params(), WalletLocation(), + + auto chain = interfaces::MakeChain(); + const CWallet wallet(Params(), *chain, WalletLocation(), WalletDatabase::CreateDummy()); + LOCK(wallet.cs_wallet); // Setup diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,9 @@ RPCServer rpcServer; HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); + InitInterfaces interfaces; + interfaces.chain = interfaces::MakeChain(); + bool fRet = false; // @@ -194,7 +198,8 @@ // If locking the data directory failed, exit immediately return false; } - fRet = AppInitMain(config, rpcServer, httpRPCRequestProcessor); + fRet = + AppInitMain(config, rpcServer, httpRPCRequestProcessor, interfaces); } catch (const std::exception &e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { @@ -206,7 +211,7 @@ } else { WaitForShutdown(); } - Shutdown(); + Shutdown(interfaces); return fRet; } diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -12,8 +12,12 @@ void AddWalletOptions() const override; bool ParameterInteraction() const override { return true; } void RegisterRPC(CRPCTable &) const override {} - bool Verify(const CChainParams &chainParams) const override { return true; } - bool Open(const CChainParams &chainParams) const override { + bool Verify(const CChainParams &chainParams, + interfaces::Chain &chain) const override { + return true; + } + bool Open(const CChainParams &chainParams, + interfaces::Chain &chain) const override { LogPrintf("No wallet support compiled in!\n"); return true; } diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -18,13 +18,24 @@ class HTTPRPCRequestProcessor; class RPCServer; +namespace interfaces { +class Chain; +class ChainClient; +} // namespace interfaces + +//! Pointers to interfaces used during init and destroyed on shutdown. +struct InitInterfaces { + std::unique_ptr chain; + std::vector> chain_clients; +}; + namespace boost { class thread_group; } // namespace boost /** Interrupt threads */ void Interrupt(); -void Shutdown(); +void Shutdown(InitInterfaces &interfaces); //! Initialize the logging infrastructure void InitLogging(); //! Parameter interaction: change current parameters depending on various rules @@ -68,7 +79,8 @@ * AppInitLockDataDirectory should have been called. */ bool AppInitMain(Config &config, RPCServer &rpcServer, - HTTPRPCRequestProcessor &httpRPCRequestProcessor); + HTTPRPCRequestProcessor &httpRPCRequestProcessor, + InitInterfaces &interfaces); /** * Setup the arguments for gArgs. diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include