diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -98,7 +98,6 @@ // only valid after this clause) try { SelectParams(args.GetChainName()); - node.chain = interfaces::MakeChain(node, config.GetChainParams()); } catch (const std::exception &e) { return InitError(Untranslated(strprintf("%s\n", e.what()))); } @@ -178,7 +177,8 @@ // If locking the data directory failed, exit immediately return false; } - fRet = AppInitMain(config, rpcServer, httpRPCRequestProcessor, node); + fRet = AppInitInterfaces(node) && + AppInitMain(config, rpcServer, httpRPCRequestProcessor, node); } catch (const std::exception &e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -69,6 +69,11 @@ * AppInitSanityChecks should have been called. */ bool AppInitLockDataDirectory(); +/** + * Initialize node and wallet interface pointers. Has no prerequisites or side + * effects besides allocating memory. + */ +bool AppInitInterfaces(NodeContext &node); /** * Bitcoin main initialization. * @note This should only be done after daemonization. diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2120,6 +2120,16 @@ return true; } +bool AppInitInterfaces(NodeContext &node) { + node.chain = interfaces::MakeChain(node, Params()); + // Create client interfaces for wallets that are supposed to be loaded + // according to -wallet and -disablewallet options. This only constructs + // the interfaces, it doesn't load wallet data. Wallets actually get loaded + // when load() and start() interface methods are called below. + g_wallet_init_interface.Construct(node); + return true; +} + bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, NodeContext &node, @@ -2237,12 +2247,6 @@ GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler); - // Create client interfaces for wallets that are supposed to be loaded - // according to -wallet and -disablewallet options. This only constructs - // the interfaces, it doesn't load wallet data. Wallets actually get loaded - // when load() and start() interface methods are called below. - g_wallet_init_interface.Construct(node); - /** * Register RPC commands regardless of -server setting so they will be * available in the GUI RPC console even if external calls are disabled. diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -76,12 +76,12 @@ bool baseInitialize(Config &config) override { return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(config, gArgs) && - AppInitSanityChecks() && AppInitLockDataDirectory(); + AppInitSanityChecks() && AppInitLockDataDirectory() && + AppInitInterfaces(*m_context); } bool appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, interfaces::BlockAndHeaderTipInfo *tip_info) override { - m_context->chain = MakeChain(*m_context, config.GetChainParams()); return AppInitMain(config, rpcServer, httpRPCRequestProcessor, *m_context, tip_info); }