This pull fixes several peer connection bugs in our p2p code, along with the logging that uncovered them:
-
Fix detection of inbound peer connections in
GetAddedNodeInfo
. -
Fix addnode CJDNS peers not detected in
GetAddedNodeInfo
, causingThreadOpenAddedConnections
to continually retry to connect to them and RPCgetaddednodeinfo
incorrectly showing them as not connected. -
Fix
ThreadOpenConnections
not detecting inbound CJDNS connections and making automatic outbound connections to them. -
Fix detection of already connected peers in
AlreadyConnectedToAddress()
. -
Fix detection of already connected peers when making outbound connections in
ConnectNode
. -
Do not accept inbound connections in
CreateNodeFromAcceptedSocket
from I2P peers we’re already connected to, as building I2P tunnels is expensive. -
Fix making automatic outbound connections in
ThreadOpenConnections
to addnode peers, in order not to allocate our limited outbound slots to them and to ensure addnode connections benefit from their intended protections. Our addnode logic usually connects the addnode peers before the automatic outbound logic does, but not always, as a connection race can occur (see the commit message for further details and mainnet examples). When an addnode peer is connected as an automatic outbound peer and is the only connection we have to a network, it can be protected by our new outbound network-specific eviction logic and persist in the “wrong role”. Fix these issues by checking if the selected address is an addnode peer in our automatic outbound connection logic.
Update the p2p logging with the improvements that allowed seeing/understanding/debugging the current behavior. Please see the commit messages for details.
Simplify MaybePickPreferredNetwork
to return std::optional
, make it a const class method, and add Clang thread-safety analysis annotation and related assertions.