Skip to content

Commit 93ab136

Browse files
author
MarcoFalke
committed
Merge bitcoin-core/gui#35: Parse params directly instead of through node (partial revert bitcoin#10244)
519cae8 gui: Delay interfaces::Node initialization (Russell Yanofsky) 102abff gui: Replace interface::Node references with pointers (Russell Yanofsky) 91aced7 gui: Remove unused interfaces::Node references (Russell Yanofsky) e133631 gui: Partially revert bitcoin#10244 gArgs and Params changes (Russell Yanofsky) Pull request description: This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10). --- This is a partial revert of bitcoin#10244. It changes gui code to go back to using gArgs and Params() functions directly instead of using interfaces::Node to handle arguments. These changes were originally pushed as part of bitcoin#19461. Motivation is to support a new GUI process connecting to an already running node process. Details are explained in commit messages, but in addition to spawning a new bitcoin-node process, we want bitcoin-gui to connect to an existing bitcoin-node process. So for that reason it should be able to parse its own parameters, rather than rely on the node. ACKs for top commit: MarcoFalke: re-ACK 519cae8, only change is rebase and addressed nits of my previous review last week 🌄 Tree-SHA512: 9c339dd82ba78bcc7b887b84d872f35ccc7dfa3d271691e6eafe8a2048cbbe3bdde1e810ce33d0714d75d048c9de3470e9e9b6f8306a6047d1cb3548f6858dc8
2 parents a12d9e5 + 519cae8 commit 93ab136

18 files changed

+125
-142
lines changed

src/interfaces/node.cpp

+2-17
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,8 @@ class NodeImpl : public Node
5757
{
5858
public:
5959
NodeImpl(NodeContext* context) { setContext(context); }
60-
void initError(const bilingual_str& message) override { InitError(message); }
61-
bool parseParameters(int argc, const char* const argv[], std::string& error) override
62-
{
63-
return gArgs.ParseParameters(argc, argv, error);
64-
}
65-
bool readConfigFiles(std::string& error) override { return gArgs.ReadConfigFiles(error, true); }
66-
void forceSetArg(const std::string& arg, const std::string& value) override { gArgs.ForceSetArg(arg, value); }
67-
bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); }
68-
bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); }
69-
void selectParams(const std::string& network) override { SelectParams(network); }
70-
bool initSettings(std::string& error) override { return gArgs.InitSettings(error); }
71-
uint64_t getAssumedBlockchainSize() override { return Params().AssumedBlockchainSize(); }
72-
uint64_t getAssumedChainStateSize() override { return Params().AssumedChainStateSize(); }
73-
std::string getNetwork() override { return Params().NetworkIDString(); }
74-
void initLogging() override { InitLogging(gArgs); }
75-
void initParameterInteraction() override { InitParameterInteraction(gArgs); }
60+
void initLogging() override { InitLogging(*Assert(m_context->args)); }
61+
void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); }
7662
bilingual_str getWarnings() override { return GetWarnings(true); }
7763
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
7864
bool baseInitialize() override
@@ -109,7 +95,6 @@ class NodeImpl : public Node
10995
StopMapPort();
11096
}
11197
}
112-
void setupServerArgs() override { return SetupServerArgs(*m_context); }
11398
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
11499
size_t getNodeCount(CConnman::NumConnections flags) override
115100
{

src/interfaces/node.h

-38
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,6 @@ class Node
5555
public:
5656
virtual ~Node() {}
5757

58-
//! Send init error.
59-
virtual void initError(const bilingual_str& message) = 0;
60-
61-
//! Set command line arguments.
62-
virtual bool parseParameters(int argc, const char* const argv[], std::string& error) = 0;
63-
64-
//! Set a command line argument
65-
virtual void forceSetArg(const std::string& arg, const std::string& value) = 0;
66-
67-
//! Set a command line argument if it doesn't already have a value
68-
virtual bool softSetArg(const std::string& arg, const std::string& value) = 0;
69-
70-
//! Set a command line boolean argument if it doesn't already have a value
71-
virtual bool softSetBoolArg(const std::string& arg, bool value) = 0;
72-
73-
//! Load settings from configuration file.
74-
virtual bool readConfigFiles(std::string& error) = 0;
75-
76-
//! Choose network parameters.
77-
virtual void selectParams(const std::string& network) = 0;
78-
79-
//! Read and update <datadir>/settings.json file with saved settings. This
80-
//! needs to be called after selectParams() because the settings file
81-
//! location is network-specific.
82-
virtual bool initSettings(std::string& error) = 0;
83-
84-
//! Get the (assumed) blockchain size.
85-
virtual uint64_t getAssumedBlockchainSize() = 0;
86-
87-
//! Get the (assumed) chain state size.
88-
virtual uint64_t getAssumedChainStateSize() = 0;
89-
90-
//! Get network name.
91-
virtual std::string getNetwork() = 0;
92-
9358
//! Init logging.
9459
virtual void initLogging() = 0;
9560

@@ -117,9 +82,6 @@ class Node
11782
//! Return whether shutdown was requested.
11883
virtual bool shutdownRequested() = 0;
11984

120-
//! Setup arguments
121-
virtual void setupServerArgs() = 0;
122-
12385
//! Map port.
12486
virtual void mapPort(bool use_upnp) = 0;
12587

src/qt/bitcoin.cpp

+46-33
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@
2727
#include <qt/walletmodel.h>
2828
#endif // ENABLE_WALLET
2929

30+
#include <init.h>
3031
#include <interfaces/handler.h>
3132
#include <interfaces/node.h>
3233
#include <node/context.h>
34+
#include <node/ui_interface.h>
3335
#include <noui.h>
3436
#include <uint256.h>
3537
#include <util/system.h>
3638
#include <util/threadnames.h>
3739
#include <util/translation.h>
3840
#include <validation.h>
3941

42+
#include <boost/signals2/connection.hpp>
4043
#include <memory>
4144

4245
#include <QApplication>
@@ -193,10 +196,9 @@ void BitcoinCore::shutdown()
193196
static int qt_argc = 1;
194197
static const char* qt_argv = "bitcoin-qt";
195198

196-
BitcoinApplication::BitcoinApplication(interfaces::Node& node):
199+
BitcoinApplication::BitcoinApplication():
197200
QApplication(qt_argc, const_cast<char **>(&qt_argv)),
198201
coreThread(nullptr),
199-
m_node(node),
200202
optionsModel(nullptr),
201203
clientModel(nullptr),
202204
window(nullptr),
@@ -246,38 +248,47 @@ void BitcoinApplication::createPaymentServer()
246248

247249
void BitcoinApplication::createOptionsModel(bool resetSettings)
248250
{
249-
optionsModel = new OptionsModel(m_node, this, resetSettings);
251+
optionsModel = new OptionsModel(this, resetSettings);
250252
}
251253

252254
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
253255
{
254-
window = new BitcoinGUI(m_node, platformStyle, networkStyle, nullptr);
256+
window = new BitcoinGUI(node(), platformStyle, networkStyle, nullptr);
255257

256258
pollShutdownTimer = new QTimer(window);
257259
connect(pollShutdownTimer, &QTimer::timeout, window, &BitcoinGUI::detectShutdown);
258260
}
259261

260262
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
261263
{
262-
SplashScreen *splash = new SplashScreen(m_node, nullptr, networkStyle);
264+
assert(!m_splash);
265+
m_splash = new SplashScreen(nullptr, networkStyle);
263266
// We don't hold a direct pointer to the splash screen after creation, but the splash
264267
// screen will take care of deleting itself when finish() happens.
265-
splash->show();
266-
connect(this, &BitcoinApplication::splashFinished, splash, &SplashScreen::finish);
267-
connect(this, &BitcoinApplication::requestedShutdown, splash, &QWidget::close);
268+
m_splash->show();
269+
connect(this, &BitcoinApplication::splashFinished, m_splash, &SplashScreen::finish);
270+
connect(this, &BitcoinApplication::requestedShutdown, m_splash, &QWidget::close);
271+
}
272+
273+
void BitcoinApplication::setNode(interfaces::Node& node)
274+
{
275+
assert(!m_node);
276+
m_node = &node;
277+
if (optionsModel) optionsModel->setNode(*m_node);
278+
if (m_splash) m_splash->setNode(*m_node);
268279
}
269280

270281
bool BitcoinApplication::baseInitialize()
271282
{
272-
return m_node.baseInitialize();
283+
return node().baseInitialize();
273284
}
274285

275286
void BitcoinApplication::startThread()
276287
{
277288
if(coreThread)
278289
return;
279290
coreThread = new QThread(this);
280-
BitcoinCore *executor = new BitcoinCore(m_node);
291+
BitcoinCore *executor = new BitcoinCore(node());
281292
executor->moveToThread(coreThread);
282293

283294
/* communication to and from thread */
@@ -298,8 +309,8 @@ void BitcoinApplication::parameterSetup()
298309
// print to the console unnecessarily.
299310
gArgs.SoftSetBoolArg("-printtoconsole", false);
300311

301-
m_node.initLogging();
302-
m_node.initParameterInteraction();
312+
InitLogging(gArgs);
313+
InitParameterInteraction(gArgs);
303314
}
304315

305316
void BitcoinApplication::InitializePruneSetting(bool prune)
@@ -331,7 +342,7 @@ void BitcoinApplication::requestShutdown()
331342
window->unsubscribeFromCoreSignals();
332343
// Request node shutdown, which can interrupt long operations, like
333344
// rescanning a wallet.
334-
m_node.startShutdown();
345+
node().startShutdown();
335346
// Unsetting the client model can cause the current thread to wait for node
336347
// to complete an operation, like wait for a RPC execution to complete.
337348
window->setClientModel(nullptr);
@@ -353,7 +364,7 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
353364
{
354365
// Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
355366
qInfo() << "Platform customization:" << platformStyle->getName();
356-
clientModel = new ClientModel(m_node, optionsModel);
367+
clientModel = new ClientModel(node(), optionsModel);
357368
window->setClientModel(clientModel, &tip_info);
358369
#ifdef ENABLE_WALLET
359370
if (WalletModel::isWalletEnabled()) {
@@ -437,9 +448,9 @@ int GuiMain(int argc, char* argv[])
437448
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);
438449

439450
// Subscribe to global signals from core
440-
std::unique_ptr<interfaces::Handler> handler_message_box = node->handleMessageBox(noui_ThreadSafeMessageBox);
441-
std::unique_ptr<interfaces::Handler> handler_question = node->handleQuestion(noui_ThreadSafeQuestion);
442-
std::unique_ptr<interfaces::Handler> handler_init_message = node->handleInitMessage(noui_InitMessage);
451+
boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
452+
boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
453+
boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage);
443454

444455
// Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
445456

@@ -453,15 +464,15 @@ int GuiMain(int argc, char* argv[])
453464
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
454465
#endif
455466

456-
BitcoinApplication app(*node);
467+
BitcoinApplication app;
457468

458469
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
459470
// Command-line options take precedence:
460-
node->setupServerArgs();
471+
SetupServerArgs(node_context);
461472
SetupUIArgs(gArgs);
462473
std::string error;
463-
if (!node->parseParameters(argc, argv, error)) {
464-
node->initError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
474+
if (!gArgs.ParseParameters(argc, argv, error)) {
475+
InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
465476
// Create a message box, because the gui has neither been created nor has subscribed to core signals
466477
QMessageBox::critical(nullptr, PACKAGE_NAME,
467478
// message can not be translated because translations have not been initialized
@@ -487,7 +498,7 @@ int GuiMain(int argc, char* argv[])
487498
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
488499
// but before showing splash screen.
489500
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
490-
HelpMessageDialog help(*node, nullptr, gArgs.IsArgSet("-version"));
501+
HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
491502
help.showOrPrint();
492503
return EXIT_SUCCESS;
493504
}
@@ -497,18 +508,18 @@ int GuiMain(int argc, char* argv[])
497508
bool did_show_intro = false;
498509
bool prune = false; // Intro dialog prune check box
499510
// Gracefully exit if the user cancels
500-
if (!Intro::showIfNeeded(*node, did_show_intro, prune)) return EXIT_SUCCESS;
511+
if (!Intro::showIfNeeded(did_show_intro, prune)) return EXIT_SUCCESS;
501512

502513
/// 6. Determine availability of data directory and parse bitcoin.conf
503514
/// - Do not call GetDataDir(true) before this step finishes
504515
if (!CheckDataDirOption()) {
505-
node->initError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
516+
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
506517
QMessageBox::critical(nullptr, PACKAGE_NAME,
507518
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
508519
return EXIT_FAILURE;
509520
}
510-
if (!node->readConfigFiles(error)) {
511-
node->initError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
521+
if (!gArgs.ReadConfigFiles(error, true)) {
522+
InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
512523
QMessageBox::critical(nullptr, PACKAGE_NAME,
513524
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
514525
return EXIT_FAILURE;
@@ -522,18 +533,18 @@ int GuiMain(int argc, char* argv[])
522533

523534
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
524535
try {
525-
node->selectParams(gArgs.GetChainName());
536+
SelectParams(gArgs.GetChainName());
526537
} catch(std::exception &e) {
527-
node->initError(Untranslated(strprintf("%s\n", e.what())));
538+
InitError(Untranslated(strprintf("%s\n", e.what())));
528539
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error: %1").arg(e.what()));
529540
return EXIT_FAILURE;
530541
}
531542
#ifdef ENABLE_WALLET
532543
// Parse URIs on command line -- this can affect Params()
533-
PaymentServer::ipcParseCommandLine(*node, argc, argv);
544+
PaymentServer::ipcParseCommandLine(argc, argv);
534545
#endif
535-
if (!node->initSettings(error)) {
536-
node->initError(Untranslated(error));
546+
if (!gArgs.InitSettings(error)) {
547+
InitError(Untranslated(error));
537548
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error initializing settings: %1").arg(QString::fromStdString(error)));
538549
return EXIT_FAILURE;
539550
}
@@ -587,6 +598,8 @@ int GuiMain(int argc, char* argv[])
587598
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
588599
app.createSplashScreen(networkStyle.data());
589600

601+
app.setNode(*node);
602+
590603
int rv = EXIT_SUCCESS;
591604
try
592605
{
@@ -609,10 +622,10 @@ int GuiMain(int argc, char* argv[])
609622
}
610623
} catch (const std::exception& e) {
611624
PrintExceptionContinue(&e, "Runaway exception");
612-
app.handleRunawayException(QString::fromStdString(node->getWarnings().translated));
625+
app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated));
613626
} catch (...) {
614627
PrintExceptionContinue(nullptr, "Runaway exception");
615-
app.handleRunawayException(QString::fromStdString(node->getWarnings().translated));
628+
app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated));
616629
}
617630
return rv;
618631
}

src/qt/bitcoin.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#endif
1111

1212
#include <QApplication>
13+
#include <assert.h>
1314
#include <memory>
1415

1516
#include <interfaces/node.h>
@@ -20,6 +21,7 @@ class NetworkStyle;
2021
class OptionsModel;
2122
class PaymentServer;
2223
class PlatformStyle;
24+
class SplashScreen;
2325
class WalletController;
2426
class WalletModel;
2527

@@ -54,7 +56,7 @@ class BitcoinApplication: public QApplication
5456
{
5557
Q_OBJECT
5658
public:
57-
explicit BitcoinApplication(interfaces::Node& node);
59+
explicit BitcoinApplication();
5860
~BitcoinApplication();
5961

6062
#ifdef ENABLE_WALLET
@@ -88,6 +90,9 @@ class BitcoinApplication: public QApplication
8890
/// Setup platform style
8991
void setupPlatformStyle();
9092

93+
interfaces::Node& node() const { assert(m_node); return *m_node; }
94+
void setNode(interfaces::Node& node);
95+
9196
public Q_SLOTS:
9297
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
9398
void shutdownResult();
@@ -102,7 +107,6 @@ public Q_SLOTS:
102107

103108
private:
104109
QThread *coreThread;
105-
interfaces::Node& m_node;
106110
OptionsModel *optionsModel;
107111
ClientModel *clientModel;
108112
BitcoinGUI *window;
@@ -114,6 +118,8 @@ public Q_SLOTS:
114118
int returnValue;
115119
const PlatformStyle *platformStyle;
116120
std::unique_ptr<QWidget> shutdownWindow;
121+
SplashScreen* m_splash = nullptr;
122+
interfaces::Node* m_node = nullptr;
117123

118124
void startThread();
119125
};

src/qt/bitcoingui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
9595
updateWindowTitle();
9696

9797
rpcConsole = new RPCConsole(node, _platformStyle, nullptr);
98-
helpMessageDialog = new HelpMessageDialog(node, this, false);
98+
helpMessageDialog = new HelpMessageDialog(this, false);
9999
#ifdef ENABLE_WALLET
100100
if(enableWallet)
101101
{
@@ -821,7 +821,7 @@ void BitcoinGUI::aboutClicked()
821821
if(!clientModel)
822822
return;
823823

824-
HelpMessageDialog dlg(m_node, this, true);
824+
HelpMessageDialog dlg(this, true);
825825
dlg.exec();
826826
}
827827

0 commit comments

Comments
 (0)