util: Make default arg values more specific #19471

pull hebasto wants to merge 3 commits into bitcoin:master from hebasto:200708-hint changing 7 files +45 −22
  1. hebasto commented at 3:28 PM on July 8, 2020: member

    This PR:

    • silents printing of the -daemon option for bitcoin-qt
    • prints the correct default value of the -printtoconsole option for bitcoin-qt
    • prints the default value of the -server option

    On master (abdfd2d0e3ebec7dbead89317ee9192189a35809):

    $ ./src/bitcoind -help  # `bitcoin-qt -help' prints the same
    ...
      -daemon
           Run in the background as a daemon and accept commands
    ...
      -printtoconsole
           Send trace/debug info to console (default: 1 when no -daemon. To disable
           logging to file, set -nodebuglogfile)
    ...
      -server
           Accept command line and JSON-RPC commands
    

    With this PR:

    $ ./src/bitcoind -help
    ...
      -daemon
           Run in the background as a daemon and accept commands
    ...
      -printtoconsole
           Send trace/debug info to console (default: 1). Disabled when -daemon=1.
           To disable logging to file, set -nodebuglogfile
    ...
      -server
           Accept command line and JSON-RPC commands (default: 1)
    
    $ ./src/qt/bitcoin-qt -help
    ...
      -printtoconsole
           Send trace/debug info to console (default: 0). To disable logging to
           file, set -nodebuglogfile
    ...
      -server
           Accept command line and JSON-RPC commands (default: 0)
    
  2. in src/util/system.h:119 in f0add14537 outdated
     114 | @@ -115,6 +115,18 @@ inline bool IsSwitchChar(char c)
     115 |  #endif
     116 |  }
     117 |  
     118 | +struct DefaultArgHints {
     119 | +    constexpr DefaultArgHints() = default;
    


    MarcoFalke commented at 3:38 PM on July 8, 2020:

    Any reason to have the default constructor and specify default values for the default args? Note that the compiler forces initialization when a member is const, so moving the initialization of the defaults to bitcoind.cpp seems cleaner.


    hebasto commented at 3:51 PM on July 8, 2020:
  3. hebasto force-pushed on Jul 8, 2020
  4. hebasto commented at 3:51 PM on July 8, 2020: member

    Updated f0add1453739be415962c1a4223c7244db4171e5 -> 6a5f5d8b3fc2dcad1b64a59fe9beacde739b578b (pr19471.01 -> pr19471.02, diff):

    Any reason to have the default constructor and specify default values for the default args? Note that the compiler forces initialization when a member is const, so moving the initialization of the defaults to bitcoind.cpp seems cleaner.

  5. DrahtBot added the label GUI on Jul 8, 2020
  6. DrahtBot added the label Tests on Jul 8, 2020
  7. DrahtBot added the label Utils/log/libs on Jul 8, 2020
  8. DrahtBot commented at 6:46 PM on July 8, 2020: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #21732 (MOVEONLY: Move common init code to init/common by ryanofsky)
    • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #10102 ([experimental] Multiprocess bitcoin by ryanofsky)

    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.

  9. DrahtBot cross-referenced this on Jul 8, 2020 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  10. DrahtBot cross-referenced this on Jul 8, 2020 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  11. DrahtBot cross-referenced this on Jul 8, 2020 from issue multiprocess: Add basic spawn and IPC support by ryanofsky
  12. DrahtBot cross-referenced this on Jul 8, 2020 from issue qt, refactor: Drop unneeded Q_DECLARE_METATYPE by hebasto
  13. DrahtBot cross-referenced this on Jul 8, 2020 from issue test: Remove duplicate NodeContext hacks by ryanofsky
  14. fanquake requested review from ryanofsky on Jul 9, 2020
  15. DrahtBot cross-referenced this on Jul 9, 2020 from issue net: Add NAT-PMP port forwarding support by hebasto
  16. DrahtBot cross-referenced this on Jul 9, 2020 from issue Add loadwallet and createwallet load_on_startup options by ryanofsky
  17. DrahtBot cross-referenced this on Jul 9, 2020 from issue interfaces: Expose settings.json methods to GUI by ryanofsky
  18. DrahtBot cross-referenced this on Jul 9, 2020 from issue Add <datadir>/settings.json persistent settings storage by ryanofsky
  19. DrahtBot cross-referenced this on Jul 9, 2020 from issue Remove the automatic creation and loading of the default wallet by achow101
  20. DrahtBot cross-referenced this on Jul 9, 2020 from issue Multiprocess bitcoin by ryanofsky
  21. DrahtBot cross-referenced this on Jul 11, 2020 from issue refactor: remove ::vpwallets and related global variables by ryanofsky
  22. DrahtBot cross-referenced this on Jul 11, 2020 from issue refactor: Move wallet methods out of chain.h and node.h by ryanofsky
  23. DrahtBot cross-referenced this on Jul 21, 2020 from issue refactor: Pass ArgsManager into functions that register args by S3RK
  24. MarcoFalke removed the label Tests on Jul 22, 2020
  25. DrahtBot added the label Needs rebase on Jul 23, 2020
  26. hebasto force-pushed on Jul 24, 2020
  27. DrahtBot removed the label Needs rebase on Jul 24, 2020
  28. hebasto force-pushed on Jul 24, 2020
  29. hebasto commented at 9:01 AM on July 24, 2020: member

    Rebased 6a5f5d8b3fc2dcad1b64a59fe9beacde739b578b -> c1030526ebbe2f36c0943a6ba9a4dac12f8fd68f (pr19471.02 -> pr19471.04) due to the conflicts with #15935 and #18923.

  30. MarcoFalke commented at 6:46 AM on July 25, 2020: member

    re-run ci

  31. MarcoFalke closed this on Jul 25, 2020

  32. MarcoFalke reopened this on Jul 25, 2020

  33. hebasto force-pushed on Jul 29, 2020
  34. hebasto commented at 12:46 PM on July 29, 2020: member

    Rebased c1030526ebbe2f36c0943a6ba9a4dac12f8fd68f -> 03bf37b51475e82f9a4df4646138a52c2d8c63f3 (pr19471.04 -> pr19471.05) to include the recent CI changes.

  35. DrahtBot added the label Needs rebase on Jul 30, 2020
  36. hebasto force-pushed on Jul 31, 2020
  37. hebasto commented at 1:29 PM on July 31, 2020: member

    Rebased 03bf37b51475e82f9a4df4646138a52c2d8c63f3 -> 96192efd58df41ae871bed2c9d3032bb221f8630 (pr19471.05 -> pr19471.06) due to the conflict with #19561.

  38. DrahtBot removed the label Needs rebase on Jul 31, 2020
  39. DrahtBot added the label Needs rebase on Aug 7, 2020
  40. hebasto force-pushed on Aug 8, 2020
  41. hebasto commented at 7:04 AM on August 8, 2020: member

    Rebased 96192efd58df41ae871bed2c9d3032bb221f8630 -> c501b996a71db82fce778375fec5482e80e506bf (pr19471.06 -> pr19471.07) due to the conflict with #19098.

  42. hebasto commented at 7:05 AM on August 8, 2020: member

    @ryanofsky Mind reviewing this PR?

  43. DrahtBot removed the label Needs rebase on Aug 8, 2020
  44. in src/util/system.h:131 in c501b996a7 outdated
     127 | @@ -128,6 +128,17 @@ inline bool IsSwitchChar(char c)
     128 |  #endif
     129 |  }
     130 |  
     131 | +struct DefaultArgHints {
    


    ryanofsky commented at 1:02 PM on August 12, 2020:

    In commit "util: Add DefaultArgHints struct" (f5e3b93076403997ce9a3e23253fdaa5514753c9)

    • I think this struct should be moved to init.h and not be in system.h, since it's defining options for SetupServerArgs and AppInit function, not interacting with the ArgsManager class or other system functions. It's fine to include init.h in gui code and https://github.com/bitcoin-core/gui/pull/35 makes the call to SetupServerArgs there more direct
    • To be a little more consistent with naming and explicit, would rename DefaultArgHints to ServerArgsOptions, and rename printtoconsole to printtoconsole_default, and rename server to server_default. I think ServerArgsOptions::gui is a better name than DefaultArgHints::gui because the gui value is used to show or hide help text, not to determine default argument values.

    hebasto commented at 4:06 PM on August 13, 2020:

    @ryanofsky Thank you for your review! Updated.

  45. ryanofsky approved
  46. ryanofsky commented at 1:11 PM on August 12, 2020: contributor

    Code review ACK c501b996a71db82fce778375fec5482e80e506bf. Suggested some naming changes below but behavior here is a clear improvement and implementation is good.

  47. hebasto force-pushed on Aug 13, 2020
  48. hebasto commented at 3:44 PM on August 13, 2020: member

    Updated c501b996a71db82fce778375fec5482e80e506bf -> 0ae8c14d8d85eda41ecb1731b9788a58e332df09 (pr19471.07 -> pr19471.08, diff):

  49. hebasto force-pushed on Aug 13, 2020
  50. hebasto commented at 4:03 PM on August 13, 2020: member

    Rebased 0ae8c14d8d85eda41ecb1731b9788a58e332df09 -> cdd6f157c1780189d2340e06122931a5b8a428c5 (pr19471.08 -> pr19471.09) due to the conflict with #19011.

  51. DrahtBot cross-referenced this on Aug 22, 2020 from issue Remove gArgs global from init by MarcoFalke
  52. ryanofsky approved
  53. ryanofsky commented at 11:05 PM on August 24, 2020: contributor

    Code review ACK cdd6f157c1780189d2340e06122931a5b8a428c5. Just rebase and naming updates (thanks!) since last review

  54. DrahtBot added the label Needs rebase on Aug 26, 2020
  55. hebasto force-pushed on Aug 26, 2020
  56. hebasto commented at 9:26 AM on August 26, 2020: member

    Rebased cdd6f157c1780189d2340e06122931a5b8a428c5 -> 88a5061217332e590948b942815083ad5625d8fe (pr19471.09 -> pr19471.10) due to the conflict with #19779.

  57. DrahtBot removed the label Needs rebase on Aug 26, 2020
  58. DrahtBot added the label Needs rebase on Aug 26, 2020
  59. hebasto force-pushed on Aug 26, 2020
  60. hebasto commented at 6:34 PM on August 26, 2020: member

    Rebased 88a5061217332e590948b942815083ad5625d8fe -> 1a02a037a53a10995892c4bd86faa663cad8f656 (pr19471.10 -> pr19471.11) due to the conflict with https://github.com/bitcoin-core/gui/pull/35.

  61. DrahtBot removed the label Needs rebase on Aug 26, 2020
  62. hebasto closed this on Aug 26, 2020

  63. hebasto reopened this on Aug 26, 2020

  64. MarcoFalke removed the label GUI on Sep 7, 2020
  65. ryanofsky approved
  66. ryanofsky commented at 12:03 PM on October 14, 2020: contributor

    Code review ACK 1a02a037a53a10995892c4bd86faa663cad8f656. No changes, just rebase and a few conflict resolutions

  67. DrahtBot cross-referenced this on Dec 31, 2020 from issue qt: Request Android permissions on APi >= 23 by BlockMechanic
  68. DrahtBot cross-referenced this on Jan 26, 2021 from issue bitcoind: Add -daemonwait option to wait for initialization by laanwj
  69. DrahtBot added the label Needs rebase on Mar 11, 2021
  70. hebasto force-pushed on Mar 16, 2021
  71. hebasto commented at 8:37 AM on March 16, 2021: member

    Rebased 1a02a037a53a10995892c4bd86faa663cad8f656 -> d796dd09dd0866f391cf5663bc8e1cc8ca1b3402 (pr19471.11 -> pr19471.12) due to the conflict with #21007.

  72. DrahtBot removed the label Needs rebase on Mar 16, 2021
  73. hebasto force-pushed on Mar 16, 2021
  74. hebasto commented at 4:02 PM on March 16, 2021: member

    Rebased d796dd09dd0866f391cf5663bc8e1cc8ca1b3402 -> 2ce271c84d7ac5cee0cb79f5f04662b8b7c42f5b (pr19471.12 -> pr19471.13) on top of the #21447.

  75. ryanofsky approved
  76. ryanofsky commented at 7:20 PM on March 31, 2021: contributor

    Code review ACK 2ce271c84d7ac5cee0cb79f5f04662b8b7c42f5b. Just rebased after conflict

  77. Add ServerArgsOptions struct
    A struct is used instead of bit flags as args could have non-boolean
    types.
    d59d2806c2
  78. Use ServerArgsOptions struct
    This change makes -help command print correct default values for some
    options.
    e7198353c7
  79. in src/qt/bitcoin.cpp:314 in 2ce271c84d outdated
     310 | @@ -309,9 +311,8 @@ void BitcoinApplication::startThread()
     311 |  
     312 |  void BitcoinApplication::parameterSetup()
     313 |  {
     314 | -    // Default printtoconsole to false for the GUI. GUI programs should not
     315 | -    // print to the console unnecessarily.
     316 | -    gArgs.SoftSetBoolArg("-printtoconsole", false);
     317 | +    gArgs.SoftSetBoolArg("-printtoconsole", SERVER_ARGS_OPTIONS.printtoconsole_default);
    


    MarcoFalke commented at 11:24 AM on April 2, 2021:

    what is the point of overwriting the arg here, but keeping the default value as !args.GetBoolArg("-daemon", false) where it is parsed? It would be cleaner to not do any overwriting here and simply use printtoconsole_default as default value.



    MarcoFalke commented at 5:41 PM on April 14, 2021:

    bitcoin-wallet is a completely separate binary that isn't even modified in this PR. I fail to see how this is relevant to the discussion?


    hebasto commented at 2:54 PM on April 18, 2021:

    @MarcoFalke

    It would be cleaner to not do any overwriting here and simply use printtoconsole_default as default value.

    Yes, you right. But at the parsing place the SERVER_ARGS_OPTIONS is out of the scope. It is possible to bring it into the scope by adding a data member to the ArgsManager but it will make a diff bigger. Is it worth it?


    MarcoFalke commented at 3:17 PM on April 18, 2021:

    Why add a data member to ArgsManager? Just pass it into InitLogging by reference?


    hebasto commented at 4:18 PM on April 18, 2021:

    Just pass it into InitLogging by reference?

    What about interfaces::Node::initLogging()?


    hebasto commented at 4:42 PM on April 18, 2021:

    what is the point of overwriting the arg here, but keeping the default value as !args.GetBoolArg("-daemon", false) where it is parsed? It would be cleaner to not do any overwriting here and simply use printtoconsole_default as default value.

    It will change the current behavior, as for bitcoind the printtoconsole_default must be disabled when the -daemon option is set.


    hebasto commented at 5:23 PM on April 18, 2021:

    @MarcoFalke

    Thanks! Updated.

  80. hebasto force-pushed on Apr 18, 2021
  81. hebasto commented at 2:50 PM on April 18, 2021: member

    Updated 2ce271c84d7ac5cee0cb79f5f04662b8b7c42f5b -> e7198353c72e7f6dcfacb4bf1cc4a284afcee0a8 (pr19471.13 -> pr19471.14, diff):

    • drop unneeded forward declaration
  82. hebasto commented at 5:21 PM on April 18, 2021: member

    Updated e7198353c72e7f6dcfacb4bf1cc4a284afcee0a8 -> ccc0388e18e1340387baa0bcdb8a812e48793721 (pr19471.14 -> pr19471.15, diff):

  83. Use ServerArgsOptions::printtoconsole_default directly ccc0388e18
  84. hebasto force-pushed on Apr 18, 2021
  85. DrahtBot cross-referenced this on Apr 20, 2021 from issue MOVEONLY: Move common init code to init/common by ryanofsky
  86. DrahtBot added the label Needs rebase on Apr 23, 2021
  87. DrahtBot commented at 9:37 AM on April 23, 2021: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  88. ryanofsky commented at 1:51 PM on April 27, 2021: contributor

    Sorry, I think I created a lot of conflicts with here with #19160 and #21732. But I think this can be rebased as a change like the diff below. In the diff I consolidated the gui printtoconsole_default server_default options into a single is_gui option in src/bitcoind.cpp and src/qt/bitcoin.cpp because I thought it might be clearer if selection of default option values didn't need to involve these files. But it didn't really clean things up very much and it would be reasonable to split the options up again if this is not a good change.

    I think this all could be cleaner after the change in #10102 adding separate BitcoinNodeInit / BitcoinWalletInit / BitcoinGuiInit / BitcoinQtInit / BitcoindInit classes, since it will be easier to add custom hooks for each executable. I will try to split that change into a smaller PR, but there is no need to delay better behavior implemented in this PR waiting for IPC stuff.

    diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
    index cf9e4fad44d..7e44ca7517d 100644
    --- a/src/bitcoind.cpp
    +++ b/src/bitcoind.cpp
    @@ -170,10 +170,8 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
                 return false;
             }
     
    -        // -server defaults to true for bitcoind but not for the GUI so do this here
    -        args.SoftSetBoolArg("-server", true);
             // Set this early so that parameter interactions go to console
    -        InitLogging(args);
    +        InitLogging(args, node.is_gui);
             InitParameterInteraction(args);
             if (!AppInitBasicSetup(args)) {
                 // InitError will have been called with detailed error, which ends up on console
    diff --git a/src/init.cpp b/src/init.cpp
    index 24d67f48dc1..09faa05f28c 100644
    --- a/src/init.cpp
    +++ b/src/init.cpp
    @@ -347,7 +347,7 @@ void SetupServerArgs(NodeContext& node)
         SetupHelpOptions(argsman);
         argsman.AddArg("-help-debug", "Print help message with debugging options and exit", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); // server-only for now
     
    -    init::AddLoggingArgs(argsman);
    +    init::AddLoggingArgs(argsman, /* can_daemonize= */ !node.is_gui, /* default_printtoconsole= */ !node.is_gui);
     
         const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
         const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
    @@ -545,11 +545,16 @@ void SetupServerArgs(NodeContext& node)
         argsman.AddArg("-rpcwhitelist=<whitelist>", "Set a whitelist to filter incoming RPC calls for a specific user. The field <whitelist> comes in the format: <USERNAME>:<rpc 1>,<rpc 2>,...,<rpc n>. If multiple whitelists are set for a given user, they are set-intersected. See -rpcwhitelistdefault documentation for information on default whitelist behavior.", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
         argsman.AddArg("-rpcwhitelistdefault", "Sets default behavior for rpc whitelisting. Unless rpcwhitelistdefault is set to 0, if any -rpcwhitelist is set, the rpc server acts as if all rpc users are subject to empty-unless-otherwise-specified whitelists. If rpcwhitelistdefault is set to 1 and no -rpcwhitelist is set, rpc server acts as if all rpc users are subject to empty whitelists.", ArgsManager::ALLOW_BOOL, OptionsCategory::RPC);
         argsman.AddArg("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
    -    argsman.AddArg("-server", "Accept command line and JSON-RPC commands", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
    +    argsman.AddArg("-server", strprintf("Accept command line and JSON-RPC commands (default: %u)", !node.is_gui), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
     
     #if HAVE_DECL_FORK
    +    if (!node.is_gui) {
         argsman.AddArg("-daemon", strprintf("Run in the background as a daemon and accept commands (default: %d)", DEFAULT_DAEMON), ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
         argsman.AddArg("-daemonwait", strprintf("Wait for initialization to be finished before exiting. This implies -daemon (default: %d)", DEFAULT_DAEMONWAIT), ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
    +    } else {
    +        hidden_args.emplace_back("-daemon");
    +        hidden_args.emplace_back("-daemonwait");
    +    }
     #else
         hidden_args.emplace_back("-daemon");
         hidden_args.emplace_back("-daemonwait");
    @@ -740,9 +745,10 @@ void InitParameterInteraction(ArgsManager& args)
      * Note that this is called very early in the process lifetime, so you should be
      * careful about what global state you rely on here.
      */
    -void InitLogging(const ArgsManager& args)
    +void InitLogging(const ArgsManager& args, bool is_gui)
     {
    -    init::SetLoggingOptions(args);
    +    init::SetLoggingOptions(args, /* is_daemon= */ args.GetBoolArg("-daemon", DEFAULT_DAEMON) || args.GetBoolArg("-daemonwait", DEFAULT_DAEMONWAIT), /* default_printtoconsole= */ !is_gui);
    +
         init::LogPackageVersion();
     }
     
    @@ -1169,7 +1175,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
          * that the server is there and will be ready later).  Warmup mode will
          * be disabled when initialisation is finished.
          */
    -    if (args.GetBoolArg("-server", false)) {
    +    if (args.GetBoolArg("-server", !node.is_gui)) {
             uiInterface.InitMessage_connect(SetRPCWarmupStatus);
             if (!AppInitServers(node))
                 return InitError(_("Unable to start HTTP server. See debug log for details."));
    diff --git a/src/init.h b/src/init.h
    index 328eda9c7e8..b0c953ab8a3 100644
    --- a/src/init.h
    +++ b/src/init.h
    @@ -28,7 +28,7 @@ class thread_group;
     void Interrupt(NodeContext& node);
     void Shutdown(NodeContext& node);
     //!Initialize the logging infrastructure
    -void InitLogging(const ArgsManager& args);
    +void InitLogging(const ArgsManager& args, bool is_gui);
     //!Parameter interaction: change current parameters depending on various rules
     void InitParameterInteraction(ArgsManager& args);
     
    diff --git a/src/init/common.cpp b/src/init/common.cpp
    index 79e0c9da782..8ba2262b4f3 100644
    --- a/src/init/common.cpp
    +++ b/src/init/common.cpp
    @@ -58,7 +58,7 @@ bool SanityChecks()
         return true;
     }
     
    -void AddLoggingArgs(ArgsManager& argsman)
    +void AddLoggingArgs(ArgsManager& argsman, bool can_daemonize, bool default_printtoconsole)
     {
         argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
         argsman.AddArg("-debug=<category>", "Output debugging information (default: -nodebug, supplying <category> is optional). "
    @@ -74,15 +74,19 @@ void AddLoggingArgs(ArgsManager& argsman)
     #endif
         argsman.AddArg("-logsourcelocations", strprintf("Prepend debug output with name of the originating source location (source file, line number and function name) (default: %u)", DEFAULT_LOGSOURCELOCATIONS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
         argsman.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
    -    argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
    +    argsman.AddArg("-printtoconsole", strprintf("Send trace/debug info to console (default: %u).%s To disable logging to file, set -nodebuglogfile", default_printtoconsole, can_daemonize ? " Disabled when -daemon=1." : ""), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
         argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
     }
     
    -void SetLoggingOptions(const ArgsManager& args)
    +void SetLoggingOptions(const ArgsManager& args, bool is_daemon, bool default_printtoconsole)
     {
         LogInstance().m_print_to_file = !args.IsArgNegated("-debuglogfile");
         LogInstance().m_file_path = AbsPathForConfigVal(args.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
    -    LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", !args.GetBoolArg("-daemon", false));
    +    if (is_daemon) {
    +        LogInstance().m_print_to_console = false;
    +    } else {
    +        LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", default_printtoconsole);
    +    }
         LogInstance().m_log_timestamps = args.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
         LogInstance().m_log_time_micros = args.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
     #ifdef HAVE_THREAD_LOCAL
    diff --git a/src/init/common.h b/src/init/common.h
    index fc4bc1b2800..6efa7917093 100644
    --- a/src/init/common.h
    +++ b/src/init/common.h
    @@ -18,8 +18,8 @@ void UnsetGlobals();
      *  necessary library support.
      */
     bool SanityChecks();
    -void AddLoggingArgs(ArgsManager& args);
    -void SetLoggingOptions(const ArgsManager& args);
    +void AddLoggingArgs(ArgsManager& argsman, bool can_daemonize, bool default_printtoconsole);
    +void SetLoggingOptions(const ArgsManager& args, bool is_daemon, bool default_printtoconsole);
     void SetLoggingCategories(const ArgsManager& args);
     bool StartLogging(const ArgsManager& args);
     void LogPackageVersion();
    diff --git a/src/node/context.h b/src/node/context.h
    index 06adb33a80e..1bdaaddb6b7 100644
    --- a/src/node/context.h
    +++ b/src/node/context.h
    @@ -39,6 +39,9 @@ class WalletClient;
     struct NodeContext {
         //! Init interface for initializing current process and connecting to other processes.
         interfaces::Init* init{nullptr};
    +    //! Bool indicating if this is a GUI process that does not support
    +    //! daemonization, and should also disable the RPC server by default.
    +    bool is_gui{false};
         std::unique_ptr<CAddrMan> addrman;
         std::unique_ptr<CConnman> connman;
         std::unique_ptr<CTxMemPool> mempool;
    diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
    index 8befbf5e307..8352936c182 100644
    --- a/src/node/interfaces.cpp
    +++ b/src/node/interfaces.cpp
    @@ -71,7 +71,7 @@ private:
         ChainstateManager& chainman() { return *Assert(m_context->chainman); }
     public:
         explicit NodeImpl(NodeContext* context) { setContext(context); }
    -    void initLogging() override { InitLogging(*Assert(m_context->args)); }
    +    void initLogging() override { InitLogging(*Assert(m_context->args), m_context->is_gui); }
         void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); }
         bilingual_str getWarnings() override { return GetWarnings(true); }
         uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
    @@ -93,7 +93,7 @@ public:
         {
             StartShutdown();
             // Stop RPC for clean shutdown if any of waitfor* commands is executed.
    -        if (gArgs.GetBoolArg("-server", false)) {
    +        if (gArgs.GetBoolArg("-server", !m_context->is_gui)) {
                 InterruptRPC();
                 StopRPC();
             }
    diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
    index de71b7dea7d..33a9c24d281 100644
    --- a/src/qt/bitcoin.cpp
    +++ b/src/qt/bitcoin.cpp
    @@ -311,11 +311,7 @@ void BitcoinApplication::startThread()
     
     void BitcoinApplication::parameterSetup()
     {
    -    // Default printtoconsole to false for the GUI. GUI programs should not
    -    // print to the console unnecessarily.
    -    gArgs.SoftSetBoolArg("-printtoconsole", false);
    -
    -    InitLogging(gArgs);
    +    InitLogging(gArgs, /* is_gui= */ true);
         InitParameterInteraction(gArgs);
     }
     
    @@ -464,6 +460,7 @@ int GuiMain(int argc, char* argv[])
         util::ThreadSetInternalName("main");
     
         NodeContext node_context;
    +    node_context.is_gui = true;
         std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);
     
         // Subscribe to global signals from core
    diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
    index ffc51151458..42793c1abf6 100644
    --- a/src/test/util/setup_common.cpp
    +++ b/src/test/util/setup_common.cpp
    @@ -101,7 +101,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
         SelectParams(chainName);
         SeedInsecureRand();
         if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN);
    -    InitLogging(*m_node.args);
    +    InitLogging(*m_node.args, m_node.is_gui);
         AppInitParameterInteraction(*m_node.args);
         LogInstance().StartLogging();
         SHA256AutoDetect();
    
  89. DrahtBot commented at 11:21 AM on December 15, 2021: contributor

    <!--13523179cfe9479db18ec6c5d236f789-->There hasn't been much activity lately and the patch still needs rebase. What is the status here?

    • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
    • Is it no longer relevant? ➡️ Please close.
    • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.
  90. DrahtBot commented at 1:07 PM on March 21, 2022: contributor

    <!--13523179cfe9479db18ec6c5d236f789-->There hasn't been much activity lately and the patch still needs rebase. What is the status here?

    • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
    • Is it no longer relevant? ➡️ Please close.
    • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.
  91. hebasto commented at 2:32 PM on April 22, 2022: member

    I won't be able to focus on this stuff in the near future.

    So closing up for grabs.

  92. hebasto closed this on Apr 22, 2022

  93. hebasto added the label Up for grabs on Apr 22, 2022
  94. bitcoin locked this on Apr 22, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:54 UTC