-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#31223: net, init: derive default onion port if …
…a user specified a -port 1dd3af8 Add release note for #31223 (Martin Zumsande) 997757d test: add functional test for -port behavior (Martin Zumsande) 0e2b12b net, init: derive default onion port if a user specified a -port (Martin Zumsande) Pull request description: This resolves #31133 (setups with multiple local nodes each using a different `-port` no longer working with v28.0, see the issue description for more details) by deriving the default onion listening port to be the value specified by `-port` incremented by 1 (idea by vasild / laanwj). Note that with this fix, the chosen `-port` values of two local nodes cannot be adjacent, otherwise there will be port collisions again. From the discussion in the linked issue, this was the most popular option, followed by doing nothing and telling affected users to change their setups to use `-bind` instead of `-port`. But more opinions are certainly welcome! I think that if we decide to do something about the problem described in the issue, we should do so soon (in 28.1.), so I opened this PR. Fixes #31133 ACKs for top commit: achow101: ACK 1dd3af8 laanwj: Tested ACK 1dd3af8 tdb3: Code review ACK 1dd3af8 Tree-SHA512: 37fda2b23bbedcab5df3a401cf5afce66ae5318fb78f9660f83e3fd075b528e8156d7a0903f9a12ffe97ab5d83860587116b74af28670a1f4c2f0d1be4999f40
- Loading branch information
Showing
9 changed files
with
94 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
P2P and network changes | ||
----------------------- | ||
When the `-port` configuration option is used, the default onion listening port will now | ||
be derived to be that port + 1 instead of being set to a fixed value (8334 on mainnet). | ||
This re-allows setups with multiple local nodes using different `-port` and not using `-bind`, | ||
which would lead to a startup failure in v28.0 due to a port collision. | ||
|
||
Note that a `HiddenServicePort` manually configured in `torrc` may need adjustment if used in | ||
connection with the `-port` option. | ||
For example, if you are using `-port=5555` with a non-standard value and not using `-bind=...=onion`, | ||
previously Bitcoin Core would listen for incoming Tor connections on `127.0.0.1:8334`. | ||
Now it would listen on `127.0.0.1:5556` (`-port` plus one). If you configured the hidden service manually | ||
in torrc now you have to change it from `HiddenServicePort 8333 127.0.0.1:8334` to `HiddenServicePort 8333 | ||
127.0.0.1:5556`, or configure bitcoind with `-bind=127.0.0.1:8334=onion` to get the previous behavior. | ||
(#31223) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2024-present The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
""" | ||
Test the -port option and its interactions with | ||
-bind. | ||
""" | ||
|
||
from test_framework.test_framework import ( | ||
BitcoinTestFramework, | ||
) | ||
from test_framework.util import ( | ||
p2p_port, | ||
) | ||
|
||
|
||
class PortTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
# Avoid any -bind= on the command line. | ||
self.bind_to_localhost_only = False | ||
self.num_nodes = 1 | ||
|
||
def run_test(self): | ||
node = self.nodes[0] | ||
node.has_explicit_bind = True | ||
port1 = p2p_port(self.num_nodes) | ||
port2 = p2p_port(self.num_nodes + 5) | ||
|
||
self.log.info("When starting with -port, bitcoind binds to it and uses port + 1 for an onion bind") | ||
with node.assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port1}', f'Bound to 127.0.0.1:{port1 + 1}']): | ||
self.restart_node(0, extra_args=["-listen", f"-port={port1}"]) | ||
|
||
self.log.info("When specifying -port multiple times, only the last one is taken") | ||
with node.assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port2}', f'Bound to 127.0.0.1:{port2 + 1}'], unexpected_msgs=[f'Bound to 0.0.0.0:{port1}']): | ||
self.restart_node(0, extra_args=["-listen", f"-port={port1}", f"-port={port2}"]) | ||
|
||
self.log.info("When specifying ports with both -port and -bind, the one from -port is ignored") | ||
with node.assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port2}'], unexpected_msgs=[f'Bound to 0.0.0.0:{port1}']): | ||
self.restart_node(0, extra_args=["-listen", f"-port={port1}", f"-bind=0.0.0.0:{port2}"]) | ||
|
||
self.log.info("When -bind specifies no port, the values from -port and -bind are combined") | ||
with self.nodes[0].assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port1}']): | ||
self.restart_node(0, extra_args=["-listen", f"-port={port1}", "-bind=0.0.0.0"]) | ||
|
||
self.log.info("When an onion bind specifies no port, the value from -port, incremented by 1, is taken") | ||
with self.nodes[0].assert_debug_log(expected_msgs=[f'Bound to 127.0.0.1:{port1 + 1}']): | ||
self.restart_node(0, extra_args=["-listen", f"-port={port1}", "-bind=127.0.0.1=onion"]) | ||
|
||
self.log.info("Invalid values for -port raise errors") | ||
self.stop_node(0) | ||
node.extra_args = ["-listen", "-port=65536"] | ||
node.assert_start_raises_init_error(expected_msg="Error: Invalid port specified in -port: '65536'") | ||
node.extra_args = ["-listen", "-port=0"] | ||
node.assert_start_raises_init_error(expected_msg="Error: Invalid port specified in -port: '0'") | ||
|
||
|
||
if __name__ == '__main__': | ||
PortTest(__file__).main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters