From 519cae8fd6e44aef3470415d7c5e12acb0acd9f4 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 6 Jul 2020 10:36:15 -0400 Subject: [PATCH] gui: Delay interfaces::Node initialization This is needed to allow bitcoin-gui to connect to existing node process with -ipcconnect instead of spawning a new process. It's possible to spawn a new bitcoin-node process without knowing the current data dir or network, but connecting to an existing bitcoin-node requires knowing the datadir and network first. --- src/qt/bitcoin.cpp | 7 ++++--- src/qt/splashscreen.cpp | 2 ++ src/qt/splashscreen.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 01799f34df4ae..e63ffdfb36f9c 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -249,7 +249,6 @@ void BitcoinApplication::createPaymentServer() void BitcoinApplication::createOptionsModel(bool resetSettings) { optionsModel = new OptionsModel(this, resetSettings); - optionsModel->setNode(node()); } void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) @@ -264,7 +263,6 @@ void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle) { assert(!m_splash); m_splash = new SplashScreen(nullptr, networkStyle); - m_splash->setNode(node()); // We don't hold a direct pointer to the splash screen after creation, but the splash // screen will take care of deleting itself when finish() happens. m_splash->show(); @@ -276,6 +274,8 @@ void BitcoinApplication::setNode(interfaces::Node& node) { assert(!m_node); m_node = &node; + if (optionsModel) optionsModel->setNode(*m_node); + if (m_splash) m_splash->setNode(*m_node); } bool BitcoinApplication::baseInitialize() @@ -465,7 +465,6 @@ int GuiMain(int argc, char* argv[]) #endif BitcoinApplication app; - app.setNode(*node); /// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these // Command-line options take precedence: @@ -599,6 +598,8 @@ int GuiMain(int argc, char* argv[]) if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) app.createSplashScreen(networkStyle.data()); + app.setNode(*node); + int rv = EXIT_SUCCESS; try { diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 50fe8eb28ba3d..bd63d6e7fb64d 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -139,10 +139,12 @@ void SplashScreen::setNode(interfaces::Node& node) assert(!m_node); m_node = &node; subscribeToCoreSignals(); + if (m_shutdown) m_node->startShutdown(); } void SplashScreen::shutdown() { + m_shutdown = true; if (m_node) m_node->startShutdown(); } diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h index dc394ac43906f..2213b02c55a30 100644 --- a/src/qt/splashscreen.h +++ b/src/qt/splashscreen.h @@ -62,6 +62,7 @@ public Q_SLOTS: int curAlignment; interfaces::Node* m_node = nullptr; + bool m_shutdown = false; std::unique_ptr m_handler_init_message; std::unique_ptr m_handler_show_progress; std::unique_ptr m_handler_load_wallet;