Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Aug 22, 2020

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.

@practicalswift
Copy link
Contributor

Concept ACK: decoupled is better than coupled!

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 22, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, 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.

Copy link
Contributor

@promag promag left a 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

MarcoFalke added 2 commits August 24, 2020 07:51
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-
@jonasschnelli
Copy link
Contributor

Concept ACK fa9d590

@maflcko
Copy link
Member Author

maflcko commented Aug 24, 2020

Thanks @promag, applied the capture-copy-lambda fixup

Copy link
Contributor

@ryanofsky ryanofsky left a 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 👍

@bitcoin bitcoin deleted a comment from StanislavKlimov95 Aug 25, 2020
Copy link
Member

@fanquake fanquake left a 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.

@fanquake fanquake merged commit 6a2ba62 into bitcoin:master Aug 26, 2020
@maflcko maflcko deleted the 2008-gArgs branch August 26, 2020 07:27
@DrahtBot DrahtBot mentioned this pull request Aug 26, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 26, 2020
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 14, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants