Skip to content

Commit 6a2ba62

Browse files
committed
Merge #19779: Remove gArgs global from init
fa9d590 scripted-diff: gArgs -> args (MarcoFalke) fa33bc2 init: Capture copy of blocknotify setting for BlockNotifyCallback (MarcoFalke) fa40017 init: Pass reference to ArgsManager around instead of relying on global (MarcoFalke) Pull request description: The gArgs global has several issues: * gArgs is used by each process (bitcoind, bitcoin-qt, bitcoin-wallet, bitcoin-cli, bitcoin-tx, ...), but it is hard to determine which arguments are actually used by each process. For example arguments that have never been registered, but are still used, will always return the fallback value. * Tests may run several sub-tests, which need different settings. So globals will have to be overwritten, but that is fragile on its own: e.g. bitcoin/bitcoin#19704 (comment) or #19511 The goal is to remove gArgs, but as a first step in that direction this pull will change gArgs in init to use a passed-in reference instead. ACKs for top commit: ryanofsky: Code review ACK fa9d590. Looks good. Nice day to remove some globals, and add some lambdas 👍 fanquake: ACK fa9d590 - I'm not as familiar with the settings & argument handling code, but this make sense, and is a step in the right direction towards a reduction in the usage of globals. Not a huge fan of the clang-formatting in the scripted diff. jonasschnelli: Concept ACK fa9d590 Tree-SHA512: ed00db5f826566c7e3b4d0b3d2ee0fc1a49a6e748e04e5c93bdd694ac7da5598749e73937047d5fce86150d764a067d2ca344ba4ae3eb2704cc5c4fa0d20940f
2 parents 92735e4 + fa9d590 commit 6a2ba62

File tree

5 files changed

+189
-198
lines changed

5 files changed

+189
-198
lines changed

src/bitcoind.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,23 @@ static bool AppInit(int argc, char* argv[])
5050

5151
util::ThreadSetInternalName("init");
5252

53-
//
54-
// Parameters
55-
//
5653
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
5754
SetupServerArgs(node);
55+
ArgsManager& args = *Assert(node.args);
5856
std::string error;
59-
if (!gArgs.ParseParameters(argc, argv, error)) {
57+
if (!args.ParseParameters(argc, argv, error)) {
6058
return InitError(Untranslated(strprintf("Error parsing command line arguments: %s\n", error)));
6159
}
6260

6361
// Process help and version before taking care about datadir
64-
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
62+
if (HelpRequested(args) || args.IsArgSet("-version")) {
6563
std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n";
6664

67-
if (gArgs.IsArgSet("-version"))
68-
{
65+
if (args.IsArgSet("-version")) {
6966
strUsage += FormatParagraph(LicenseInfo()) + "\n";
70-
}
71-
else
72-
{
67+
} else {
7368
strUsage += "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n";
74-
strUsage += "\n" + gArgs.GetHelpMessage();
69+
strUsage += "\n" + args.GetHelpMessage();
7570
}
7671

7772
tfm::format(std::cout, "%s", strUsage);
@@ -82,14 +77,14 @@ static bool AppInit(int argc, char* argv[])
8277
try
8378
{
8479
if (!CheckDataDirOption()) {
85-
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""))));
80+
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""))));
8681
}
87-
if (!gArgs.ReadConfigFiles(error, true)) {
82+
if (!args.ReadConfigFiles(error, true)) {
8883
return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
8984
}
9085
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
9186
try {
92-
SelectParams(gArgs.GetChainName());
87+
SelectParams(args.GetChainName());
9388
} catch (const std::exception& e) {
9489
return InitError(Untranslated(strprintf("%s\n", e.what())));
9590
}
@@ -101,23 +96,21 @@ static bool AppInit(int argc, char* argv[])
10196
}
10297
}
10398

104-
if (!gArgs.InitSettings(error)) {
99+
if (!args.InitSettings(error)) {
105100
InitError(Untranslated(error));
106101
return false;
107102
}
108103

109104
// -server defaults to true for bitcoind but not for the GUI so do this here
110-
gArgs.SoftSetBoolArg("-server", true);
105+
args.SoftSetBoolArg("-server", true);
111106
// Set this early so that parameter interactions go to console
112-
InitLogging();
113-
InitParameterInteraction();
114-
if (!AppInitBasicSetup())
115-
{
107+
InitLogging(args);
108+
InitParameterInteraction(args);
109+
if (!AppInitBasicSetup(args)) {
116110
// InitError will have been called with detailed error, which ends up on console
117111
return false;
118112
}
119-
if (!AppInitParameterInteraction())
120-
{
113+
if (!AppInitParameterInteraction(args)) {
121114
// InitError will have been called with detailed error, which ends up on console
122115
return false;
123116
}
@@ -126,8 +119,7 @@ static bool AppInit(int argc, char* argv[])
126119
// InitError will have been called with detailed error, which ends up on console
127120
return false;
128121
}
129-
if (gArgs.GetBoolArg("-daemon", false))
130-
{
122+
if (args.GetBoolArg("-daemon", false)) {
131123
#if HAVE_DECL_DAEMON
132124
#if defined(MAC_OSX)
133125
#pragma GCC diagnostic push

0 commit comments

Comments
 (0)