Skip to content

Commit b266b3e

Browse files
committed
refactor: Create interfaces earlier during initialization
Add AppInitInterfaces function so wallet chain and chain client interfaces are created earlier during initialization. This is needed in the next commit to allow the gui splash screen to be able to register for wallet events through a dedicated WalletClient interface instead managing wallets indirectly through the Node interface. This only works if the wallet client interface is created before the splash screen needs to use it.
1 parent 15886b0 commit b266b3e

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/bitcoind.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ static void WaitForShutdown(NodeContext& node)
4444
static bool AppInit(int argc, char* argv[])
4545
{
4646
NodeContext node;
47-
node.chain = interfaces::MakeChain(node);
4847

4948
bool fRet = false;
5049

@@ -144,7 +143,7 @@ static bool AppInit(int argc, char* argv[])
144143
// If locking the data directory failed, exit immediately
145144
return false;
146145
}
147-
fRet = AppInitMain(context, node);
146+
fRet = AppInitInterfaces(node) && AppInitMain(context, node);
148147
}
149148
catch (const std::exception& e) {
150149
PrintExceptionContinue(&e, "AppInit()");

src/init.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,17 @@ bool AppInitLockDataDirectory()
12291229
return true;
12301230
}
12311231

1232+
bool AppInitInterfaces(NodeContext& node)
1233+
{
1234+
node.chain = interfaces::MakeChain(node);
1235+
// Create client interfaces for wallets that are supposed to be loaded
1236+
// according to -wallet and -disablewallet options. This only constructs
1237+
// the interfaces, it doesn't load wallet data. Wallets actually get loaded
1238+
// when load() and start() interface methods are called below.
1239+
g_wallet_init_interface.Construct(node);
1240+
return true;
1241+
}
1242+
12321243
bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12331244
{
12341245
const ArgsManager& args = *Assert(node.args);
@@ -1318,12 +1329,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
13181329

13191330
GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
13201331

1321-
// Create client interfaces for wallets that are supposed to be loaded
1322-
// according to -wallet and -disablewallet options. This only constructs
1323-
// the interfaces, it doesn't load wallet data. Wallets actually get loaded
1324-
// when load() and start() interface methods are called below.
1325-
g_wallet_init_interface.Construct(node);
1326-
13271332
/* Register RPC commands regardless of -server setting so they will be
13281333
* available in the GUI RPC console even if external calls are disabled.
13291334
*/

src/init.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ bool AppInitSanityChecks();
5252
* @pre Parameters should be parsed and config file should be read, AppInitSanityChecks should have been called.
5353
*/
5454
bool AppInitLockDataDirectory();
55+
/**
56+
* Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
57+
*/
58+
bool AppInitInterfaces(NodeContext& node);
5559
/**
5660
* Bitcoin core main initialization.
5761
* @note This should only be done after daemonization. Call Shutdown() if this function fails.

src/interfaces/node.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ class NodeImpl : public Node
6464
bool baseInitialize() override
6565
{
6666
return AppInitBasicSetup(gArgs) && AppInitParameterInteraction(gArgs) && AppInitSanityChecks() &&
67-
AppInitLockDataDirectory();
67+
AppInitLockDataDirectory() && AppInitInterfaces(*m_context);
6868
}
6969
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
7070
{
71-
m_context->chain = MakeChain(*m_context);
7271
return AppInitMain(m_context_ref, *m_context, tip_info);
7372
}
7473
void appShutdown() override

0 commit comments

Comments
 (0)