If the bitcoind starts when listen=0 but listenonion=1, the daemon will advertise its onion address but nothing is listening for it.
This update will enforce listenonion=0 when the listen is 0.
If the bitcoind starts when listen=0 but listenonion=1, the daemon will advertise its onion address but nothing is listening for it.
This update will enforce listenonion=0 when the listen is 0.
507 | @@ -508,6 +508,7 @@ void SetupServerArgs(NodeContext& node) 508 | argsman.AddArg("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); 509 | argsman.AddArg("-checkpoints", strprintf("Enable rejection of any forks from the known historical chain until block %s (default: %u)", defaultChainParams->Checkpoints().GetHeight(), DEFAULT_CHECKPOINTS_ENABLED), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); 510 | argsman.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); 511 | + argsman.AddArg("-dropmessagestest=<n>", "Randomly drop 1 of every <n> network messages", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
This line does not look like it belongs to this PR
no. what is this? my mistake on copy paste from another check. sorry.
removed this line
hi @jadijadi, welcome to the project!
if a PR gets merged, the commits get preserved in the history on master. here, it looks like the first commit introduces an extraneous change that gets removed in the second commit. please squash them so there are just relevant changes.
hi @jadijadi, welcome to the project!
if a PR gets merged, the commits get preserved in the history on master. here, it looks like the first commit introduces an extraneous change that gets removed in the second commit. please squash them so there are just relevant changes.
Thanks @amitiuttarwar for the welcome, help and being this patient with newcomers :) squashed them into one.
Concept ACK.
This would fix https://github.com/bitcoin/bitcoin/issues/20657
826 | @@ -827,8 +827,10 @@ void InitParameterInteraction(ArgsManager& args) 827 | LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__); 828 | if (args.SoftSetBoolArg("-discover", false)) 829 | LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__); 830 | - if (args.SoftSetBoolArg("-listenonion", false)) 831 | + if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) { 832 | + args.ForceSetArg("-listenonion", std::string("0"));
The rest of InitParameterInteraction() uses SoftSetBoolArg() which I guess is to avoid overriding a value that has been explicitly set by the user. InitParameterInteraction() only flips defaults. I think this behavior is sensible as it minimizes the user's surprise.
There is some other code which refuses to start the application if incompatible options are given - for example -prune=1 -txindex=1 or -bind=addr:port -listen=0.
Given the above, what about refusing to start if -listen=0 -listenonion=1 is explicitly given?
I think refusing to start (with an error message?) over changing what the user has set is better
Agree with you guys. Will update the PR to refuse the start instead of changing the explicitly set parameter.
I think refusing to start (with an error message?) over changing what the user has set is better
I've sent a new PR with this behavior. Refusing to start looks more UNIXish.
The rest of
InitParameterInteraction()usesSoftSetBoolArg()which I guess is to avoid overriding a value that has been explicitly set by the user.InitParameterInteraction()only flips defaults. I think this behavior is sensible as it minimizes the user's surprise.There is some other code which refuses to start the application if incompatible options are given - for example
-prune=1 -txindex=1or-bind=addr:port -listen=0.Given the above, what about refusing to start if
-listen=0 -listenonion=1is explicitly given?
Thanks for the idea. I've updated the PR with this behavior.
831 | + if (args.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION)) { 832 | + args.ForceSetArg("-listenonion", std::string("0")); 833 | LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__); 834 | + } 835 | } 836 |
moved it to the bottom. thanks for the hint
Concept ACK, but this needs changes to InitParameterInteraction to handle -connect and -proxy cleanly (perhaps if -listenonion is explicitly set true, soft-set -listen true also, as with -bind at the top?).
Concept ACK, but this needs changes to
InitParameterInteractionto handle-connectand-proxycleanly (perhaps if-listenonionis explicitly set true, soft-set-listentrue also, as with-bindat the top?).
Thanks @luke-jr for the ACK and suggestion. In the initial PR, I was doing this in InitParameterInteraction as you said. But after above discussions, others suggested to do it here and preventing the system from start if the user explicitly set listenionion=1 and listen=0. In all other cases, the system handles the situation properly since the DEFAULT_LISTEN is 1 and DEFAULT_LISTEN_ONION is also 1.
Concept ACK I have not tested the code, but I have reviewed it and it looks OK, I agree it can be merged
b743feca5bcbdf95ac4993c7b371d05ef1324d99 looks good. The commit message and PR description need to be updated because they refer to the previous incarnation of this PR where it enforced listenonion=0.
It works as expected:
$ bitcoind -listen=0
InitParameterInteraction: parameter interaction: -listen=0 -> setting -listenonion=0
$ bitcoind -listen=0 -listenonion=1
Error: Cannot set -listen=0 together with -listenonion=1
this needs changes to InitParameterInteraction to handle -connect and -proxy cleanly (perhaps if -listenonion is explicitly set true, soft-set -listen true also, as with -bind at the top?).
I am not sure I understand. -listen is true by default, so if only bitcoind -listenonion=1 is given, then soft-set -listen to true would be a noop?
ACK b743feca5bcbdf95ac4993c7b371d05ef1324d99, Tested on macOS 11.2
Confirming the bug referenced here on master. This PR creates an InitParameterInteraction to set listenonion=0 when listen=0. This functionality works as intended in my testing.
Setting listen=0
2021-03-04T04:46:56Z InitParameterInteraction: parameter interaction: -listen=0 -> setting -listenonion=0
Attempting to set both listen and listenonion
Error: Cannot set -listen=0 together with -listenonion=1
@jadijadi as others have stated you may want to fix the commit message, how about this as a suggestion for the title:
net: do not advertise address where nobody is listening
If the bitcoind starts when listen=0 but listenonion=1, the daemon will
advertise its onion address but nothing is listening for it.
This update will enforce listenonion=0 when the listen is 0.
fixes #20657
ACK a38137479bf5e25bf65a62e46b81fc43fb3df75c
ACK a38137479bf5e25bf65a62e46b81fc43fb3df75c
Compiled successfully for Windows using the instructions mentioned here: https://github.com/bitcoin/bitcoin/blob/master/doc/build-windows.md
1 test failed and this is what I see in logs:

ACK a38137479bf5e25bf65a62e46b81fc43fb3df75c
with several thoughts & questions for further improvements:
-listen has a lot of parameter interactions, I'm wondering if any other conflicts should similarly cause a failure-to-start instead of quietly failing, eg -discover, i2pacceptincoming... (cc @vasild if you have more insight into some of these params)-connect=1.1.1.1 with -listenonion=1. that seems reasonable but would be nice to capture these sorts of complexities.* I'm wondering if any other conflicts should similarly cause a failure-to-start instead of quietly failing, eg `-discover`, `i2pacceptincoming`
If -listen=0 is given and -i2pacceptincoming=... is not given, then the default of the latter is flipped from 1 to 0. If both are explicitly set: -listen=0 -i2pacceptincoming=1 then it works as instructed - no binding/listening on local address:port of the machine, but accept incoming I2P connections (they do not need binding/listening, so we don't have a bug like the one with Tor which the current PR aims to resolve).
Is -listen=0 -i2pacceptincoming=1 contradictory? Maybe, to some extent, it can be perceived as such. Should we abort startup if that is given? Maybe, I am not sure. (but if yes, then that is out of the scope of this PR).
this change also disallows setting
-connect=1.1.1.1with-listenonion=1
Right. That can be worked around with -connect=1.1.1.1 -listen=1 -listenonion=1.
It seems this PR introduced a bug in the GUI: bitcoin-core/gui#567.