Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Aug 17, 2021

Make it possible to disable the Tor binding on 127.0.0.1:8334 and stop startup if any P2P bind fails instead of "if all P2P binds fail".

Fixes #22726
Fixes #22727

@vasild
Copy link
Contributor Author

vasild commented Aug 17, 2021

cc @hebasto

@DrahtBot DrahtBot added the P2P label Aug 17, 2021
@jonatack
Copy link
Member

  • The test changes seems sporadic (and often pass on master for me locally)
  • Would 1597069 disable our inbound onion detection? (CNode::m_inbound_onion in net.h)

@vasild
Copy link
Contributor Author

vasild commented Aug 17, 2021

Would 1597069 disable our inbound onion detection? (CNode::m_inbound_onion in net.h)

  • If both -bind=... and -bind=...=onion are given -- no
  • If none of -bind=... or -bind=...=onion are given -- no
  • If only -bind=... is given, without -bind=...=onion -- yes
  • If only -bind=...=onion is given, without -bind=... -- no

@fanquake fanquake requested a review from laanwj August 18, 2021 01:03
@fanquake
Copy link
Member

CI failure https://cirrus-ci.com/task/5600680695037952:

89/217 - feature_bind_extra.py failed, Duration: 31 s
stdout:
2021-08-17T14:41:23.064000Z TestFramework (INFO): Initializing test directory /tmp/cirrus-ci-build/ci/scratch/test_runner/test_runner_₿_🏃_20210817_143957/feature_bind_extra_170
2021-08-17T14:41:23.064000Z TestFramework (INFO): Checking for Linux
2021-08-17T14:41:53.701000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 530, in start_nodes
    node.wait_for_rpc_connection()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_node.py", line 225, in wait_for_rpc_connection
    'bitcoind exited with status {} during initialization'.format(self.process.returncode)))
test_framework.test_node.FailedToStartError: [node 0] bitcoind exited with status 1 during initialization
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 130, in main
    self.setup()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 285, in setup
    self.setup_network()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/feature_bind_extra.py", line 95, in setup_network
    self.setup_nodes()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 404, in setup_nodes
    self.start_nodes()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 533, in start_nodes
    self.stop_nodes()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 548, in stop_nodes
    node.stop_node(wait=wait, wait_until_stopped=False)
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_node.py", line 323, in stop_node
    self.stop(wait=wait)
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_node.py", line 183, in __getattr__
    assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
AssertionError: [node 0] Error: no RPC connection
2021-08-17T14:41:53.753000Z TestFramework (INFO): Stopping nodes

@Rspigler
Copy link
Contributor

#20234 For reference for related changes.

I might propose some Tor doc clarifications in a separate PR. There has been a lot of confusion around onlynet, and users thinking that that affects outgoing and incoming connections.

@laanwj
Copy link
Member

laanwj commented Sep 15, 2021

Concept ACK (will review in more detail). It would be better if any error in binding configuration stopped the process, not just onion-related ones, as it can lead to surprising outcomes. But historically there were some issues with libevent in getting this right see #14968.

@vasild
Copy link
Contributor Author

vasild commented Sep 16, 2021

f89f80ef2d...57e0c5d32e: rebase and stop startup if any* of the P2P binds fail, instead of all.

*except the bind on IPv6 any address :: when the user did not explicitly ask for it because the machine may not have IPv6 support.

It would be better if any error in binding configuration stopped the process, not just onion-related ones, as it can lead to surprising outcomes.

I agree. Changed. If we want to also do the same for * then we would have to check whether socket(2) failed due to EAFNOSUPPORT or bind(2) failed due to EADDRNOTAVAIL. I think that would be an overkill.

@vasild vasild changed the title Make it possible to disable and check for error in -bind=...=onion Make it possible to disable onion binds and abort startup on bind failure Sep 16, 2021
@vasild vasild changed the title Make it possible to disable onion binds and abort startup on bind failure Make it possible to disable Tor binds and abort startup on bind failure Sep 16, 2021
@vasild
Copy link
Contributor Author

vasild commented Sep 16, 2021

The first commit ceeb317 net: don't extra bind for Tor if binds are restricted was part of #20234 but was removed so that PR could proceed quickly (it was deemed controversial).

After #22727 (comment) I am even more convinced that this is the right approach as it reduces user surprises (and those surprises can have highly undesirable outcomes). It must be possible to disable the binding on 127.0.0.1:8334 somehow. Otherwise, if we consider those binds fatal, two bitcoinds would collide on that port.

For example our functional testing framework starts >1 bitcoind and all of them collide on 127.0.0.1:8334 but the bind errors are ignored 👀. If we are to consider bind errors fatal (I think we should) and ceeb317 net: don't extra bind for Tor if binds are restricted is not desirable, then the testing framework would need to be adjusted to avoid the collisions. I don't object this, but I am not going to implement it because I think the approach in this PR is a better one. I would review other approaches if somebody bothers to go in another direction.

@laanwj
Copy link
Member

laanwj commented Sep 27, 2021

For example our functional testing framework starts >1 bitcoind and all of them collide on 127.0.0.1:8334 but the bind errors are ignored eyes

There is no reason for the test framework to be creating Tor binds at all. It's kind of surprising to me that it does by default but I understand why.

I think the long term solution would be to only create the Tor bind when either requested through a command line flag, or when it succesfully connects to Tor (e.g. in torcontrol). But this would require dynamically changing (at least adding) bindings so isn't very straightforward.

@vasild
Copy link
Contributor Author

vasild commented Jun 13, 2022

57e0c5d32e...3d54f24f02: rebase due to conflicts

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 30, 2022

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK cbergqvist, pinheadmz, achow101
Concept ACK laanwj, stratospher, jonatack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28710 (Remove the legacy wallet and BDB dependency by achow101)

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.

@vasild
Copy link
Contributor Author

vasild commented Oct 25, 2022

3d54f24f02...7180859e7e: rebase due to conflicts

@vasild
Copy link
Contributor Author

vasild commented Nov 14, 2022

I think the long term solution would be to only create the Tor bind when either requested through a command line flag, or when it succesfully connects to Tor (e.g. in torcontrol)

This would also help binding on the proper address and announcing it to the tor daemon. If tor and bitcoind run on the same machine the default 127.0.0.1 works smoothly.

But it gets more involved in setups where tor is on another machine. Then the default -bind=127.0.0.1:8334=onion is not ok anymore and the operator has to use something like -torcontrol=192.168.0.5:9051 -bind=192.168.0.6:8334=onion. Looks easy enough, but is further complicated in environments where IP addresses are dynamically set up (DHCP, Docker) and the fact that we don't resolve the argument to -bind= so a hostname can't be used there.

There is also the special case -bind=0.0.0.0:8334=onion - then we would tell the tor daemon that the service is listening on 0.0.0.0:8334 and it will not be able to connect to it.

If we postpone the binding to after we have connected to tor control, then we can automatically figure out the best address to bind to and announce that (if one is not explicitly configured).

#26484 is related, thanks @schildbach!

In the Tor case, this prevents us from telling the Tor daemon to send
our incoming connections from the Tor network to an address where we
do not listen (we tried to listen but failed probably because another
application is already listening).

In the other cases (IPv4/IPv6 binds) this also prevents unpleasant
surprises caused by continuing operations even on bind failure. For
example, another application may be listening on portX, bitcoind tries
to bind on portX and portY, only succeeds with portY and continues
operation leaving the user thinking that his bitcoind is listening on
portX whereas another application is listening (the error message in
the log could easily be missed).

Avoid having the functional testing framework start multiple `bitcoind`s
that try to listen on the same `127.0.0.1:18445` (Tor listen for
regtest) if `bind_to_localhost_only` is set to `False`.

Also fix a typo in `test-shell.md` related to `bind_to_localhost_only`.

Fixes bitcoin#22727
@vasild
Copy link
Contributor Author

vasild commented Jul 2, 2024

ffe9b27498...bca346a970: take minor suggestion which I forgot earlier: use expected_services instead of self.expected[i][1] in the test.

Copy link
Contributor

@cbergqvist cbergqvist left a comment

Choose a reason for hiding this comment

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

ACK bca346a

The current solution means most test nodes in the functional test suite will now bind to an onion port even though the vast majority are not testing Tor

Only tests that use bind_to_localhost_only will do. We have 5 such tests.

We have 5 tests that disable bind_to_localhost_only, all the others will bind=127.0.0.1. Having that will result in your new has_explicit_bind being true for the majority of tests, which will lead to your later added binds not being set for the majority of tests.
=> So only the 5 tests that disable bind_to_localhost_only will get into this Tor exception. Good, thanks for correcting me on how many tests are impacted!

The previous incarnation of this PR (8c30871) had the tests not bind on Tor, because it is not needed (the vast majority are not testing Tor), but you did not like that.

What I do not like is the special casing inside of test_node.py that feels like a dirty workaround to me instead of having individual tests pass in the arguments they require (such as -listenonion), which in turn leads to binding of otherwise inactive Tor ports. But looking back at the comment history I understand how bitcoind behaves by default might be the underlying reason preventing this cleaner proposal from being implemented.

@DrahtBot DrahtBot requested a review from pinheadmz July 3, 2024 23:17
Copy link
Member

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

ACK bca346a

Changes since last ACK extremely minimal, cleaning up one line in the test

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK bca346a97056748f1e3fb899f336d56d9fd45a64
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmaRhAIACgkQ5+KYS2KJ
yTr7nA//Sq7hxrI2I5/n/paZ+F6aMbZSxIkv7ynizzr3WfzBimoFmh+RcXkpyg5I
OK32DfJbKod4U1EgkTXY6RkjF8uYftCqLugF9qwDKC4NhkWQxEjepxX75Vrs2qtr
mZkg49HMpxb6Kj3xm/Mulj0cEgKcIyxlrNPN/AeQq/M+iBEymkBTNBMVowipAh9Z
b/B74kPiA5/D2Lk8Xp4ffd2JFpVyScDXa9CgJv7kg6mS/Jr3V/kQJ6EaIBJlcCPZ
iag0HdTXkrXOjOKDhLPgMn4sENOKBPQtpTvlZTmkyVFEAdiDo2aFaZGUwQrbRILk
GDeuQqLKWHk7ypgW3oevUzdEtfKTO2vf53m2VuzM4opQTgyx9F5OzQbYPHDc+oKQ
K3Lsort48CIReEkXnnVdtkifmJLUnDyV3qpBB2r7TMoT144089kjPbbkPafjVTzL
05l4QeAnNLS5ERrm9wTBKiSzxassRNSMOS2gH4RgWmbixchSrq0PCTJc+TBYIrRi
uLUaqZDJZTsIHw+c789nmfG08PT6r9i5LDWBEGMF176lffkuKaXD1eB7nn0wHzWQ
nS8wHmGLND4NXNJiM5j1jPnuBuHwB3ZYVab6eqzaKO3ovTfh1xzHPr5K8OksxRHP
jwwUhWJ9t6VEUZM6g/NnfA8wmGYb9F//45o3YiPol6+kNW4QKrA=
=m0K0
-----END PGP SIGNATURE-----

pinheadmz's public key is on keybase

@achow101
Copy link
Member

ACK bca346a

@achow101 achow101 merged commit 45750f6 into bitcoin:master Jul 16, 2024
@vasild vasild deleted the torbind branch July 17, 2024 07:48
vasild added a commit to vasild/bitcoin that referenced this pull request Jul 23, 2024
vasild added a commit to vasild/bitcoin that referenced this pull request Jul 23, 2024
vasild added a commit to vasild/bitcoin that referenced this pull request Jul 31, 2024
davidgumberg added a commit to davidgumberg/bitcoin that referenced this pull request Aug 1, 2024
After \bitcoin#22729, if a `-bind` is set, we no longer bind `127.0.0.1:8334`
as an onion port by default.
vasild pushed a commit to vasild/bitcoin that referenced this pull request Aug 2, 2024
After bitcoin#22729 if
`-bind=127.0.0.1` is used, then bitcoind will not automatically
also bind on `127.0.0.1:8334`.
glozow added a commit that referenced this pull request Aug 5, 2024
6d33e13 doc: tor.md: use -bind=127.0.0.1:8334=onion for the Tor bind (David Gumberg)
a7f5d18 doc: add release notes for #22729 (Vasil Dimov)

Pull request description:

  Add release notes for #22729.

ACKs for top commit:
  davidgumberg:
    reACK 6d33e13
  willcl-ark:
    ACK 6d33e13

Tree-SHA512: 9d7e66ee1d0bb1d75b8273707d30f20915d5040a768c2c5cd47c84997df2645c8bec35db6c09dc77ab917836622411b924373816cbc83c4be38e2e9156a139d8
achow101 added a commit to achow101/bitcoin that referenced this pull request Sep 3, 2024
When the bind option is replaced in the bitcoin.conf, bitcoind will
attempd to bind to the default tor listening port. If another bitcoind
is running that is already bound to that port, the bind will fail which,
since bitcoin#22729, causes the test to fail.
achow101 added a commit to achow101/bitcoin that referenced this pull request Sep 3, 2024
When the bind option is replaced in the bitcoin.conf, bitcoind will
attempd to bind to the default tor listening port. If another bitcoind
is running that is already bound to that port, the bind will fail which,
since bitcoin#22729, causes the test to fail.

This failure can be avoided by explicitly binding the tor port when the
bind is removed.
achow101 added a commit to achow101/bitcoin that referenced this pull request Sep 10, 2024
When the bind option is replaced in the bitcoin.conf, bitcoind will
attempd to bind to the default tor listening port. If another bitcoind
is running that is already bound to that port, the bind will fail which,
since bitcoin#22729, causes the test to fail.

This failure can be avoided by explicitly binding the tor port when the
bind is removed.
achow101 added a commit to achow101/bitcoin that referenced this pull request Sep 10, 2024
When the bind option is replaced in the bitcoin.conf, bitcoind will
attempd to bind to the default tor listening port. If another bitcoind
is running that is already bound to that port, the bind will fail which,
since bitcoin#22729, causes the test to fail.

This failure can be avoided by explicitly binding the tor port when the
bind is removed.
glozow added a commit that referenced this pull request Sep 11, 2024
082779d test: Add explicit onion bind to p2p_permissions (Ava Chow)

Pull request description:

  When the bind option is replaced in the bitcoin.conf, bitcoind will attempd to bind to the default tor listening port. If another bitcoind is running that is already bound to that port, the bind will fail which, since #22729, causes the test to fail.

  This failure can be avoided by explicitly binding the tor port when the bind is removed.

ACKs for top commit:
  tdb3:
    ACK 082779d
  theStack:
    re-ACK 082779d
  glozow:
    ACK 082779d

Tree-SHA512: 4acb69ea2e00aeacf9e7c9ab9595ceaf0e0d2adbd795602034b2184197d9bad54c7bc9f3da43ef9c52a71869fe96ba8c87fc5b7c37880f258f5a2aaab2b4046c
noelportillo

This comment was marked as off-topic.

janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Jan 6, 2025
After bitcoin/bitcoin#22729 if
`-bind=127.0.0.1` is used, then bitcoind will not automatically
also bind on `127.0.0.1:8334`.
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 13, 2025
Summary:
```
Make it possible to disable the Tor binding on 127.0.0.1:8334 and stop startup if any P2P bind fails instead of "if all P2P binds fail".
```

Backport of [[bitcoin/bitcoin#22729 | core#22729]].

Depends on D17661.

Test Plan:
  ninja check-functional

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Subscribers: PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17662
roqqit pushed a commit to doged-io/doged that referenced this pull request May 2, 2025
Summary:
```
Make it possible to disable the Tor binding on 127.0.0.1:8334 and stop startup if any P2P bind fails instead of "if all P2P binds fail".
```

Backport of [[bitcoin/bitcoin#22729 | core#22729]].

Depends on D17661.

Test Plan:
  ninja check-functional

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Subscribers: PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No check is done whether the binding for Tor succeeded before using it for ADD_ONION It is impossible to switch off binding for Tor