Skip to content

Commit e133631

Browse files
committed
gui: Partially revert #10244 gArgs and Params changes
Change gui code to use gArgs, Params() functions directly instead of going through interfaces::Node. Remotely accessing bitcoin-node ArgsManager from bitcoin-gui works fine in bitcoin/bitcoin#10102, when bitcoin-gui spawns a new bitcoin-node process and controls its startup, but for bitcoin-gui to support -ipcconnect option in bitcoin/bitcoin#19461 and connect to an existing bitcoin-node process, it needs ability to parse arguments itself before connecting out. This change also simplifies bitcoin/bitcoin#10102 a bit, by making the bitcoin-gui -> bitcoin-node startup sequence more similar to the bitcoin-node -> bitcoin-wallet startup sequence where the parent process parses arguments and passes them to the child process instead of the parent process using the child process to parse arguments.
1 parent a12d9e5 commit e133631

File tree

7 files changed

+37
-87
lines changed

7 files changed

+37
-87
lines changed

src/interfaces/node.cpp

Lines changed: 2 additions & 17 deletions
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

Lines changed: 0 additions & 38 deletions
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

Lines changed: 18 additions & 15 deletions
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>
@@ -298,8 +301,8 @@ void BitcoinApplication::parameterSetup()
298301
// print to the console unnecessarily.
299302
gArgs.SoftSetBoolArg("-printtoconsole", false);
300303

301-
m_node.initLogging();
302-
m_node.initParameterInteraction();
304+
InitLogging(gArgs);
305+
InitParameterInteraction(gArgs);
303306
}
304307

305308
void BitcoinApplication::InitializePruneSetting(bool prune)
@@ -437,9 +440,9 @@ int GuiMain(int argc, char* argv[])
437440
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);
438441

439442
// 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);
443+
boost::signals2::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
444+
boost::signals2::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
445+
boost::signals2::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage);
443446

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

@@ -457,11 +460,11 @@ int GuiMain(int argc, char* argv[])
457460

458461
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
459462
// Command-line options take precedence:
460-
node->setupServerArgs();
463+
SetupServerArgs(node_context);
461464
SetupUIArgs(gArgs);
462465
std::string error;
463-
if (!node->parseParameters(argc, argv, error)) {
464-
node->initError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
466+
if (!gArgs.ParseParameters(argc, argv, error)) {
467+
InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
465468
// Create a message box, because the gui has neither been created nor has subscribed to core signals
466469
QMessageBox::critical(nullptr, PACKAGE_NAME,
467470
// message can not be translated because translations have not been initialized
@@ -502,13 +505,13 @@ int GuiMain(int argc, char* argv[])
502505
/// 6. Determine availability of data directory and parse bitcoin.conf
503506
/// - Do not call GetDataDir(true) before this step finishes
504507
if (!CheckDataDirOption()) {
505-
node->initError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
508+
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
506509
QMessageBox::critical(nullptr, PACKAGE_NAME,
507510
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
508511
return EXIT_FAILURE;
509512
}
510-
if (!node->readConfigFiles(error)) {
511-
node->initError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
513+
if (!gArgs.ReadConfigFiles(error, true)) {
514+
InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
512515
QMessageBox::critical(nullptr, PACKAGE_NAME,
513516
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
514517
return EXIT_FAILURE;
@@ -522,18 +525,18 @@ int GuiMain(int argc, char* argv[])
522525

523526
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
524527
try {
525-
node->selectParams(gArgs.GetChainName());
528+
SelectParams(gArgs.GetChainName());
526529
} catch(std::exception &e) {
527-
node->initError(Untranslated(strprintf("%s\n", e.what())));
530+
InitError(Untranslated(strprintf("%s\n", e.what())));
528531
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error: %1").arg(e.what()));
529532
return EXIT_FAILURE;
530533
}
531534
#ifdef ENABLE_WALLET
532535
// Parse URIs on command line -- this can affect Params()
533536
PaymentServer::ipcParseCommandLine(*node, argc, argv);
534537
#endif
535-
if (!node->initSettings(error)) {
536-
node->initError(Untranslated(error));
538+
if (!gArgs.InitSettings(error)) {
539+
InitError(Untranslated(error));
537540
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error initializing settings: %1").arg(QString::fromStdString(error)));
538541
return EXIT_FAILURE;
539542
}

src/qt/intro.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <config/bitcoin-config.h>
77
#endif
88

9+
#include <chainparams.h>
910
#include <fs.h>
1011
#include <qt/intro.h>
1112
#include <qt/forms/ui_intro.h>
@@ -199,13 +200,13 @@ bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& pru
199200
{
200201
/* Use selectParams here to guarantee Params() can be used by node interface */
201202
try {
202-
node.selectParams(gArgs.GetChainName());
203+
SelectParams(gArgs.GetChainName());
203204
} catch (const std::exception&) {
204205
return false;
205206
}
206207

207208
/* If current default data directory does not exist, let the user choose one */
208-
Intro intro(0, node.getAssumedBlockchainSize(), node.getAssumedChainStateSize());
209+
Intro intro(0, Params().AssumedBlockchainSize(), Params().AssumedChainStateSize());
209210
intro.setDataDirectory(dataDir);
210211
intro.setWindowIcon(QIcon(":icons/bitcoin"));
211212
did_show_intro = true;
@@ -242,7 +243,7 @@ bool Intro::showIfNeeded(interfaces::Node& node, bool& did_show_intro, bool& pru
242243
* (to be consistent with bitcoind behavior)
243244
*/
244245
if(dataDir != GUIUtil::getDefaultDataDirectory()) {
245-
node.softSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
246+
gArgs.SoftSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
246247
}
247248
return true;
248249
}

src/qt/optionsmodel.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ void OptionsModel::Init(bool resetSettings)
9797

9898
if (!settings.contains("nDatabaseCache"))
9999
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
100-
if (!m_node.softSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
100+
if (!gArgs.SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
101101
addOverriddenOption("-dbcache");
102102

103103
if (!settings.contains("nThreadsScriptVerif"))
104104
settings.setValue("nThreadsScriptVerif", DEFAULT_SCRIPTCHECK_THREADS);
105-
if (!m_node.softSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString()))
105+
if (!gArgs.SoftSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString()))
106106
addOverriddenOption("-par");
107107

108108
if (!settings.contains("strDataDir"))
@@ -112,27 +112,27 @@ void OptionsModel::Init(bool resetSettings)
112112
#ifdef ENABLE_WALLET
113113
if (!settings.contains("bSpendZeroConfChange"))
114114
settings.setValue("bSpendZeroConfChange", true);
115-
if (!m_node.softSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool()))
115+
if (!gArgs.SoftSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool()))
116116
addOverriddenOption("-spendzeroconfchange");
117117
#endif
118118

119119
// Network
120120
if (!settings.contains("fUseUPnP"))
121121
settings.setValue("fUseUPnP", DEFAULT_UPNP);
122-
if (!m_node.softSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
122+
if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
123123
addOverriddenOption("-upnp");
124124

125125
if (!settings.contains("fListen"))
126126
settings.setValue("fListen", DEFAULT_LISTEN);
127-
if (!m_node.softSetBoolArg("-listen", settings.value("fListen").toBool()))
127+
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool()))
128128
addOverriddenOption("-listen");
129129

130130
if (!settings.contains("fUseProxy"))
131131
settings.setValue("fUseProxy", false);
132132
if (!settings.contains("addrProxy"))
133133
settings.setValue("addrProxy", GetDefaultProxyAddress());
134134
// Only try to set -proxy, if user has enabled fUseProxy
135-
if (settings.value("fUseProxy").toBool() && !m_node.softSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
135+
if ((settings.value("fUseProxy").toBool() && !gArgs.SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString())))
136136
addOverriddenOption("-proxy");
137137
else if(!settings.value("fUseProxy").toBool() && !gArgs.GetArg("-proxy", "").empty())
138138
addOverriddenOption("-proxy");
@@ -142,15 +142,15 @@ void OptionsModel::Init(bool resetSettings)
142142
if (!settings.contains("addrSeparateProxyTor"))
143143
settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
144144
// Only try to set -onion, if user has enabled fUseSeparateProxyTor
145-
if (settings.value("fUseSeparateProxyTor").toBool() && !m_node.softSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString()))
145+
if ((settings.value("fUseSeparateProxyTor").toBool() && !gArgs.SoftSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString())))
146146
addOverriddenOption("-onion");
147147
else if(!settings.value("fUseSeparateProxyTor").toBool() && !gArgs.GetArg("-onion", "").empty())
148148
addOverriddenOption("-onion");
149149

150150
// Display
151151
if (!settings.contains("language"))
152152
settings.setValue("language", "");
153-
if (!m_node.softSetArg("-lang", settings.value("language").toString().toStdString()))
153+
if (!gArgs.SoftSetArg("-lang", settings.value("language").toString().toStdString()))
154154
addOverriddenOption("-lang");
155155

156156
language = settings.value("language").toString();
@@ -244,10 +244,10 @@ void OptionsModel::SetPruneEnabled(bool prune, bool force)
244244
const int64_t prune_target_mib = PruneGBtoMiB(settings.value("nPruneSize").toInt());
245245
std::string prune_val = prune ? ToString(prune_target_mib) : "0";
246246
if (force) {
247-
m_node.forceSetArg("-prune", prune_val);
247+
gArgs.ForceSetArg("-prune", prune_val);
248248
return;
249249
}
250-
if (!m_node.softSetArg("-prune", prune_val)) {
250+
if (!gArgs.SoftSetArg("-prune", prune_val)) {
251251
addOverriddenOption("-prune");
252252
}
253253
}

src/qt/paymentserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
9797
auto tempChainParams = CreateChainParams(CBaseChainParams::MAIN);
9898

9999
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
100-
node.selectParams(CBaseChainParams::MAIN);
100+
SelectParams(CBaseChainParams::MAIN);
101101
} else {
102102
tempChainParams = CreateChainParams(CBaseChainParams::TESTNET);
103103
if (IsValidDestinationString(r.address.toStdString(), *tempChainParams)) {
104-
node.selectParams(CBaseChainParams::TESTNET);
104+
SelectParams(CBaseChainParams::TESTNET);
105105
}
106106
}
107107
}

src/qt/test/test_main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ int main(int argc, char* argv[])
7171
BitcoinApplication app(*node);
7272
app.setApplicationName("Bitcoin-Qt-test");
7373

74-
node->setupServerArgs(); // Make gArgs available in the NodeContext
75-
node->context()->args->ClearArgs(); // Clear added args again
74+
node->context()->args = &gArgs; // Make gArgs available in the NodeContext
7675
AppTests app_tests(app);
7776
if (QTest::qExec(&app_tests) != 0) {
7877
fInvalid = true;

0 commit comments

Comments
 (0)