If -bind= is provided with a :port part or if -whitebind= is provided (it is required to always have :port) and they contain non-standard port, then the wrong listening port will be assumed - the value of -port= or the default 8333 (if -port= is not provided). We would not be listening on that.
1.
Expected behavior
If -bind=addr1:P -externalip=addr2 is provided then we would listen on port P and our site should be self-advertised as addr2:P.
Actual behavior
We would self-advertise as addr2:Q, whereas nobody is listening on port Q (the value of -port= or the default 8333).
To reproduce
Run bitcoind with -bind= providing a routable address (127.0.0.1 or 10.0.0.1 will not suffice) and port: bitcoind -bind=138.68.248.245:9000 -externalip=138.0.0.1, observe that 138.0.0.1:8333 is in localaddresses: bitcoin-cli getnetworkinfo |jq .localaddresses.
During p2p handshake we receive a version message from the peer that contains our address:port [1] as perceived and claimed by the peer.
2.
Expected behavior
During initial self-advertise we may relay [1] to the peer for outbound connections. In this case we should override the :port part with our actual listening port.
Actual behavior
The port gets overriden with the value of -port= or the default 8333.
To reproduce
Run in gdb.
3.
Expected behavior
During periodic self-advertise we may relay [1] to the peer. We should use the address from the version message and for port:
- for outbound connections: our actual listening port
- for inbound connections: the port the peer told us in [1]
Actual behavior
The port gets overriden with the value of -port= or the default 8333, regardless of whether it is an outbound or inbound connection.
To reproduce
Run in gdb.
4.
Expected behavior
If -discover is enabled and -bind=addr:port is used then during startup we should assume as local address just addr:port.
Actual behavior
During startup we assume the addresses from all interfaces of the machine with a bogus port (the value of -port= or the default 8333). For example if the machine has two interfaces with addresses 1.1.1.1 and 2.2.2.2 and -bind=1.1.1.1:9000 is used, then we would wrongly assume and self-advertise 1.1.1.1:8333 and 2.2.2.2:8333.
To reproduce
Similar to 1.: bitcoin-cli getnetworkinfo |jq .localaddresses
5.
Expected behavior
If UPnP is enabled, we ask the router for its external IP address, assume that external address for self-advertise and set up a port mapping “external port on the router -> our internal address:port”. We should use a correct port that we actually listen to.
Actual behavior
Wrong port is used and mapping is redirected to a port on which nobody is listening.
To reproduce
Use -bind=10.0.0.1:9000 and check with the router that a mapping like “external_address_on_router:8333 -> 10.0.0.1:8333” is set.