Skip to content

Conversation

@jadijadi
Copy link
Contributor

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.

@amitiuttarwar
Copy link
Contributor

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.

@jadijadi
Copy link
Contributor Author

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.

@Rspigler
Copy link
Contributor

Concept ACK.

This would fix #20657

src/init.cpp Outdated
Comment on lines 830 to 831
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think refusing to start (with an error message?) over changing what the user has set is better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with you guys. Will update the PR to refuse the start instead of changing the explicitly set parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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?

Thanks for the idea. I've updated the PR with this behavior.

@jadijadi
Copy link
Contributor Author

jadijadi commented Jan 2, 2021

Concept ACK.

This would fix #20657

Thanks for initial ACK. but based on the comment from @vasild I updated the PR for a more UNIXish behavior: refusing to start with incompatible inputs.

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.

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?).

@jadijadi
Copy link
Contributor Author

jadijadi commented Jan 6, 2021

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?).

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.

Copy link

@felipsoarez felipsoarez 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
I have not tested the code, but I have reviewed it and it looks OK, I agree it can be merged

@vasild
Copy link
Contributor

vasild commented Jan 14, 2021

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

@luke-jr

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?

Copy link
Contributor

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

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 bitcoin#20657
@jadijadi jadijadi force-pushed the fixes-issue-20657 branch from b743fec to a381374 Compare March 16, 2021 16:05
@jadijadi
Copy link
Contributor Author

ACK b743fec, Tested on macOS 11.2

...

net: do not advertise address where nobody is listening

Thanks for the hints. I've updated the PR with the suggested commit message

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK a381374

Copy link
Contributor

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK a381374

@ghost
Copy link

ghost commented Mar 17, 2021

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:

image

Copy link
Contributor

@amitiuttarwar amitiuttarwar left a comment

Choose a reason for hiding this comment

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

ACK a381374

with several thoughts & questions for further improvements:

  • the init params are hard to keep track of & dependent on ordering, so it would be good to add a regression test. @jadijadi - I have a draft here (amitiuttarwar@ec622d1) if you'd like to include in this PR or add as a follow-up.
  • -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)
  • also would be cool to add test coverage to make explicit the other parameter interactions. for example, this change also disallows setting -connect=1.1.1.1 with -listenonion=1. that seems reasonable but would be nice to capture these sorts of complexities.

@fanquake fanquake requested a review from ajtowns August 19, 2021 00:55
@vasild
Copy link
Contributor

vasild commented Aug 20, 2021

* 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.1 with -listenonion=1

Right. That can be worked around with -connect=1.1.1.1 -listen=1 -listenonion=1.

@maflcko maflcko merged commit 58b559f into bitcoin:master Aug 23, 2021
@jadijadi jadijadi deleted the fixes-issue-20657 branch August 23, 2021 07:09
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 23, 2021
…ere nobody is listening

a381374 net: do not advertise address where nobody is listening (Jadi)

Pull request description:

  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.

ACKs for top commit:
  vasild:
    ACK a381374
  jarolrod:
    ACK a381374
  amitiuttarwar:
    ACK a381374

Tree-SHA512: e84a0a9a51f2217edf35d06c6cd9085d1e664452655ba92027195a1e88ba081d157310c84e9709a99ce5d46c94f231477ca2d36f010648b0c8b4f2a737d54e5d
@hebasto
Copy link
Member

hebasto commented Mar 22, 2022

It seems this PR introduced a bug in the GUI: bitcoin-core/gui#567.

@bitcoin bitcoin locked and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.