net: require P2P binds to succeed

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 https://github.com/bitcoin/bitcoin/issues/22727
This commit is contained in:
Vasil Dimov
2021-08-13 10:33:24 +02:00
parent af552534ab
commit bca346a970
4 changed files with 43 additions and 12 deletions

View File

@@ -309,9 +309,9 @@ def sha256sum_file(filename):
# The maximum number of nodes a single test can spawn
MAX_NODES = 12
# Don't assign rpc or p2p ports lower than this
# Don't assign p2p, rpc or tor ports lower than this
PORT_MIN = int(os.getenv('TEST_RUNNER_PORT_MIN', default=11000))
# The number of ports to "reserve" for p2p and rpc, each
# The number of ports to "reserve" for p2p, rpc and tor, each
PORT_RANGE = 5000
@@ -351,7 +351,11 @@ def p2p_port(n):
def rpc_port(n):
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
return p2p_port(n) + PORT_RANGE
def tor_port(n):
return p2p_port(n) + PORT_RANGE * 2
def rpc_url(datadir, i, chain, rpchost):