Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Apr 12, 2022

This drops the No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port> error when a empty -proxy= command line argument, bitcoin.conf value, or settings.json value is specified, and just makes bitcoin connect and listen normally in these cases.

The error was originally added in #20003 to prevent a bare -proxy command line argument with no assignment from clearing proxy settings. But it was implemented in an overbroad way breaking empty -proxy= assignments as well.

The motivation for this change is to prevent a GUI bug that happens with #15936, reported in #15936 (review) by vasild, that happens after a proxy setting is enabled and disabled in the GUI. But this change also makes sense on its own to remove a potentially confusing error message.

@hebasto
Copy link
Member

hebasto commented Apr 12, 2022

Concept ACK.

@hebasto
Copy link
Member

hebasto commented Apr 12, 2022

Should -proxy= in the command line still ends with an error for reasons discussed in #20003?

@jonatack
Copy link
Member

Concept ACK

Copy link
Contributor

@brunoerg brunoerg 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

@ryanofsky
Copy link
Contributor Author

Renamed PR from "init: Allow -noproxy and -proxy="" setting values" to "init: Allow -proxy="" setting values" because I was wrong that -noproxy was broken before this PR. -noproxy was actually working correctly.

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Apr 12, 2022

Should -proxy= in the command line still ends with an error for reasons discussed in #20003?

Bitcoin treats bare arguments (-txindex, -blocksonly, -server, etc) as being true, and it's reasonable a user might see a bare -proxy argument and interpret that as meaning "use a proxy" instead of "don't use a proxy". That is the case which #20003 describes, and makes into an error to alert the user. This case is still an error after this PR.

The problem is #20003 also forbids setting no proxy with -proxy= or -proxy="" shell arguments that are explicit assignments. I think it would be better in those cases to allow the assignments than disallow them. Obviously there is some chance a user could be confused in those cases as well, but keeping ability to assign an empty value makes sense logically, avoids needing to add special case logic in Qt to fix #15936 (review), and is a nice convenience.

More broadly, I think it is a bad thing that ArgsManager does not make a distinction between -foo and -foo= command line arguments. I think generally for boolean settings -mybool should be allowed and -mybool= should be treated as an ambiguous error. For string settings -mystring= should be allowed and -mystring should be treated as an ambiguous error. This PR enables making this distinction for the -proxy argument in a general way that could be applied to other string arguments. (It's less general and flexible than #16545 but still compatible with it and other approaches.)

@ryanofsky ryanofsky changed the title init: Allow -noproxy and -proxy="" setting values init: Allow -proxy="" setting values Apr 12, 2022
@bitcoin bitcoin deleted a comment from joshuadbryant1985 Apr 12, 2022
@ryanofsky
Copy link
Contributor Author

ryanofsky commented Apr 12, 2022

Updated 6a51a91 -> 93e83a4 (pr/proxy.1 -> pr/proxy.2, compare) dropping InitParameterInteraction change and moving it to separate PR (#24837)
Updated 93e83a4 -> c241778 (pr/proxy.2 -> pr/proxy.3, compare) tweaking error message

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 12, 2022

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

Conflicts

No conflicts as of last run.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK c241778.

@@ -175,6 +175,7 @@ class ArgsManager
// ALLOW_STRING = 0x08, //!< unimplemented, draft implementation in #16545
// ALLOW_LIST = 0x10, //!< unimplemented, draft implementation in #16545
DISALLOW_NEGATION = 0x20, //!< disallow -nofoo syntax
DISALLOW_ELISION = 0x40, //!< disallow -foo syntax that doesn't assign any value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c241778

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

But I would prefer a two-commit approach, fixing the bug simpler in commit 1, and refactoring in commit 2. (And only backporting the first commit)

@ryanofsky
Copy link
Contributor Author

But I would prefer a two-commit approach, fixing the bug simpler in commit 1, and refactoring in commit 2. (And only backporting the first commit)

This sounds appealing, but what is the simpler fix that could be backported? The problem is that ArgsManager currently stores -proxy= and -proxy command line arguments the exact same way with any way to distinguish them. So you need some change to ArgsManager in order to allow -proxy= again without allowing -proxy. So I could split this up into two commits, the first changing ArgsManager, and the second allowing -proxy= again, but you'd still need to backport both commits. (Also, I'm not sure this PR strictly needs to be backported, but I can see how it's a good candidate.)

@luke-jr
Copy link
Member

luke-jr commented Apr 14, 2022

I thought maybe a default/compare with "\0"s, and/or a combination with GetBoolArg might do the trick, but you're right, I don't see a clean solution.

@luke-jr
Copy link
Member

luke-jr commented Apr 15, 2022

This hack seems to work, but maybe not worth it? idk

diff --git a/src/init.cpp b/src/init.cpp
index a3d53c3fae9..8e8db27f676 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -98,6 +98,8 @@
 #include <zmq/zmqrpc.h>
 #endif
 
+using namespace std::literals::string_literals;
+
 using node::CacheSizes;
 using node::CalculateCacheSizes;
 using node::ChainstateLoadVerifyError;
@@ -1025,7 +1027,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
 
     nMaxTipAge = args.GetIntArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
 
-    if (args.IsArgSet("-proxy") && args.GetArg("-proxy", "").empty()) {
+    if (args.IsArgSet("-proxy") && args.GetArg("-proxy", "") == "\0"s) {
         return InitError(_("No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>."));
     }
 
diff --git a/src/util/system.cpp b/src/util/system.cpp
index aa9122106bd..4e89b4cbbd3 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -78,6 +78,8 @@
 #include <thread>
 #include <typeinfo>
 
+using namespace std::literals::string_literals;
+
 // Application startup time (used for uptime calculation)
 const int64_t nStartupTime = GetTime();
 
@@ -360,6 +362,11 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
         std::optional<util::SettingsValue> value = InterpretValue(keyinfo, val, *flags, error);
         if (!value) return false;
 
+        if (is_index == std::string::npos && keyinfo.name == "proxy") {
+            assert(value->get_str() == "");
+            value = "\0"s;
+        }
+
         m_settings.command_line_options[keyinfo.name].push_back(*value);
     }
 

@ryanofsky
Copy link
Contributor Author

This hack seems to work, but maybe not worth it? idk

This is pretty twisted and I love it. It solves the issue described minimally, like a key in a lock. But even the current full PR is only 14 lines, and I'm assuming straightforward to backport, and I think doesn't even need to be backported, so I think there's not a need for it to be so minimal. But the diff is good to have in case any issues come up, or to provide an example of how to usefully abuse char(0).

@luke-jr
Copy link
Member

luke-jr commented Apr 15, 2022

(It might or might not break the actual proxy code tho)

@ryanofsky
Copy link
Contributor Author

(It might or might not break the actual proxy code tho)

I was assuming it wouldn't do that because it keeps the InitError, but it's true init codepath is not straightforward so it's not obvious this is safe

maflcko pushed a commit that referenced this pull request Apr 17, 2022
…th other settings

3429d67 init: Prevent -noproxy and -proxy=0 settings from interacting with other settings (Ryan Ofsky)

Pull request description:

  Prevent `-noproxy` and `-proxy=0` settings from interacting with `-listen`, `-upnp`, and `-natpmp` settings.

  These settings started being handled inconsistently in the `AppInitMain` and `InitParameterInteraction` functions starting in commit baf0507 from #6272:

  https://github.com/bitcoin/bitcoin/blob/baf05075fae2cc2625a2a74b35cc66902f3cbfa3/src/init.cpp#L990-L991
  https://github.com/bitcoin/bitcoin/blob/baf05075fae2cc2625a2a74b35cc66902f3cbfa3/src/init.cpp#L687

  This commit changes both functions to handle proxy arguments the same way so
  there are not side effects from specifying a proxy=0 setting.

  This change was originally part of #24830 but really is independent and makes more sense as a separate PR

ACKs for top commit:
  hebasto:
    ACK 3429d67, tested on Ubuntu 22.04.

Tree-SHA512: c4c6b4aeb3c07321700e974c16fd47a1bd3d469f273a6b308a69638db81c88c4e67208fddc96fcda9c8bd85f3ae22c98ca131c9622895edaa34eb65c194f35db
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 18, 2022
…ting with other settings

3429d67 init: Prevent -noproxy and -proxy=0 settings from interacting with other settings (Ryan Ofsky)

Pull request description:

  Prevent `-noproxy` and `-proxy=0` settings from interacting with `-listen`, `-upnp`, and `-natpmp` settings.

  These settings started being handled inconsistently in the `AppInitMain` and `InitParameterInteraction` functions starting in commit baf0507 from bitcoin#6272:

  https://github.com/bitcoin/bitcoin/blob/baf05075fae2cc2625a2a74b35cc66902f3cbfa3/src/init.cpp#L990-L991
  https://github.com/bitcoin/bitcoin/blob/baf05075fae2cc2625a2a74b35cc66902f3cbfa3/src/init.cpp#L687

  This commit changes both functions to handle proxy arguments the same way so
  there are not side effects from specifying a proxy=0 setting.

  This change was originally part of bitcoin#24830 but really is independent and makes more sense as a separate PR

ACKs for top commit:
  hebasto:
    ACK 3429d67, tested on Ubuntu 22.04.

Tree-SHA512: c4c6b4aeb3c07321700e974c16fd47a1bd3d469f273a6b308a69638db81c88c4e67208fddc96fcda9c8bd85f3ae22c98ca131c9622895edaa34eb65c194f35db
luke-jr added a commit to luke-jr/bitcoin that referenced this pull request Apr 19, 2022
@luke-jr
Copy link
Member

luke-jr commented Apr 19, 2022

Suggest cherry-picking tests from 70dc6b6#diff-2babd91c181a89aaeb4a2bd610c8b6bcab0f0b4f5dd20251a3ad0e1742b56380

Edit: Nevermind, those don't work since all the settings are set

This drops the `No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>`
error when a empty `-proxy=` command line argument, `bitcoin.conf` value, or
`settings.json` value is specified, and just makes bitcoin connect and listen
normally in these cases.

The error was originally added in bitcoin#20003
to prevent a bare `-proxy` command line argument with no assignment from
clearing proxy settings. But it was implemented in an overbroad way breaking
empty `-proxy=` assignments as well.

The motivation for this change is to prevent a GUI bug that happens with
bitcoin#15936, reported in
bitcoin#15936 (review) by
vasild, that happens after a proxy setting is enabled and disabled in the GUI.
But this change also makes sense on its own to remove a potentially confusing
error message.
@ryanofsky
Copy link
Contributor Author

Rebased c241778 -> c657f00 (pr/proxy.3 -> pr/proxy.4, compare) due to conflict with #24789

@ryanofsky
Copy link
Contributor Author

Updated c657f00 -> 1d4122d (pr/proxy.4 -> pr/proxy.5, compare) fixing accidentally reverted python test change in previous push

@ryanofsky
Copy link
Contributor Author

ryanofsky commented May 19, 2022

Ping for maintainers. Can this be merged? It's a small change that's had two acks and a decent amount of discussion. It should be a straightforward (if minor) UX improvement, and it helps with #15936.

(I can ask for more reviewers if needed. Just want to make sure this didn't fall of the radar)

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 1d4122d, only rebased since my recent review.

Tested on Ubuntu 22.04.

@maflcko maflcko merged commit 4a87098 into bitcoin:master May 20, 2022
luke-jr added a commit to luke-jr/bitcoin that referenced this pull request May 21, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
@bitcoin bitcoin locked and limited conversation to collaborators May 20, 2023
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.

8 participants