-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Remove gArgs global from init #19779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Concept ACK: decoupled is better than coupled! |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
In fa88257 instead of binding args, could do this
@@ -1828,19 +1828,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
}
#if HAVE_SYSTEM
- if (args.IsArgSet("-blocknotify")) {
- const auto BlockNotifyCallback = [&args](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
- if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex)
- return;
-
- std::string strCmd = args.GetArg("-blocknotify", "");
- if (!strCmd.empty()) {
- boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
- std::thread t(runCommand, strCmd);
- t.detach(); // thread runs free
- }
- };
- uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
+ std::string blocknotify = args.GetArg("-blocknotify", "");
+ if (!blocknotify.empty()) {
+ uiInterface.NotifyBlockTip_connect([blocknotify](SynchronizationState sync_state, const CBlockIndex* pBlockIndex) {
+ if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) return;
+ auto strCmd = blocknotify;
+ boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
+ std::thread t(runCommand, strCmd);
+ t.detach(); // thread runs free
+ });
}
#endif
Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
-BEGIN VERIFY SCRIPT- # Replace gArgs with args sed -i 's/\<gArgs\>/args/g' src/init.cpp src/bitcoind.cpp sed -i 's/&args;/\&gArgs;/g' src/init.cpp # Format changed lines git diff -U0 | clang-format-diff -p1 -i -v -END VERIFY SCRIPT-
Concept ACK fa9d590 |
Thanks @promag, applied the capture-copy-lambda fixup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK fa9d590. Looks good. Nice day to remove some globals, and add some lambdas 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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#19704 (comment) or bitcoin#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
Summary: ``` 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. #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. ``` Backport of core [[bitcoin/bitcoin#19779 | PR19779]]. Depends on D8644 and D8645. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8646
The gArgs global has several issues:
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.