Skip to content

Commit fad4fa7

Browse files
author
MarcoFalke
committed
node: Add args alias for gArgs global
1 parent 4bd6bc5 commit fad4fa7

File tree

7 files changed

+14
-6
lines changed

7 files changed

+14
-6
lines changed

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static bool AppInit(int argc, char* argv[])
5353
// Parameters
5454
//
5555
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
56-
SetupServerArgs();
56+
SetupServerArgs(node);
5757
std::string error;
5858
if (!gArgs.ParseParameters(argc, argv, error)) {
5959
return InitError(strprintf("Error parsing command line arguments: %s\n", error));

src/init.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ void Shutdown(NodeContext& node)
297297
GetMainSignals().UnregisterBackgroundSignalScheduler();
298298
globalVerifyHandle.reset();
299299
ECC_Stop();
300+
node.args = nullptr;
300301
if (node.mempool) node.mempool = nullptr;
301302
node.scheduler.reset();
302303

@@ -360,8 +361,11 @@ static void OnRPCStopped()
360361
LogPrint(BCLog::RPC, "RPC stopped.\n");
361362
}
362363

363-
void SetupServerArgs()
364+
void SetupServerArgs(NodeContext& node)
364365
{
366+
assert(!node.args);
367+
node.args = &gArgs;
368+
365369
SetupHelpOptions(gArgs);
366370
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); // server-only for now
367371

src/init.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ bool AppInitLockDataDirectory();
5454
bool AppInitMain(NodeContext& node);
5555

5656
/**
57-
* Setup the arguments for gArgs
57+
* Register all arguments with the ArgsManager
5858
*/
59-
void SetupServerArgs();
59+
void SetupServerArgs(NodeContext& node);
6060

6161
/** Returns licensing information (for -version) */
6262
std::string LicenseInfo();

src/interfaces/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class NodeImpl : public Node
9797
StopMapPort();
9898
}
9999
}
100-
void setupServerArgs() override { return SetupServerArgs(); }
100+
void setupServerArgs() override { return SetupServerArgs(m_context); }
101101
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
102102
size_t getNodeCount(CConnman::NumConnections flags) override
103103
{

src/node/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <vector>
1010

11+
class ArgsManager;
1112
class BanMan;
1213
class CConnman;
1314
class CScheduler;
@@ -33,6 +34,7 @@ struct NodeContext {
3334
CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
3435
std::unique_ptr<PeerLogicValidation> peer_logic;
3536
std::unique_ptr<BanMan> banman;
37+
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
3638
std::unique_ptr<interfaces::Chain> chain;
3739
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
3840
std::unique_ptr<CScheduler> scheduler;

src/test/util/setup_common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ TestingSetup::~TestingSetup()
159159
g_rpc_node = nullptr;
160160
m_node.connman.reset();
161161
m_node.banman.reset();
162+
m_node.args = nullptr;
162163
m_node.mempool = nullptr;
163164
m_node.scheduler.reset();
164165
UnloadBlockIndex();

src/test/util/setup_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ static constexpr CAmount CENT{1000000};
7373
*/
7474
struct BasicTestingSetup {
7575
ECCVerifyHandle globalVerifyHandle;
76+
NodeContext m_node;
7677

7778
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
7879
~BasicTestingSetup();
80+
7981
private:
8082
const fs::path m_path_root;
8183
};
@@ -84,7 +86,6 @@ struct BasicTestingSetup {
8486
* Included are coins database, script check threads setup.
8587
*/
8688
struct TestingSetup : public BasicTestingSetup {
87-
NodeContext m_node;
8889
boost::thread_group threadGroup;
8990

9091
explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);

0 commit comments

Comments
 (0)