Skip to content

Commit a0d737c

Browse files
committed
Merge bitcoin/bitcoin#32073: net: Block v2->v1 transport downgrade if !fNetworkActive
6869fb4 net: Block v2->v1 transport downgrade if !CConnman::fNetworkActive (Hodlinator) Pull request description: We might have just set `CNode::fDisconnect` in the first loop because of `!CConnman::fNetworkActive`. Attempting to reconnect using v1 transport just because `fNetworkActive` was set to `false` at the "right" stage in the v2 handshake does not make sense. Issue [discovered](bitcoin/bitcoin#31633 (comment)) by davidgumberg. ACKs for top commit: davidgumberg: Tested and Reviewed ACK 6869fb4 mabu44: ACK 6869fb4 stratospher: ACK 6869fb4. I've reviewed the code but don't have strong preference for this branch vs master since only functional change is just a single log not being printed in a low probability scenario (we happen to be attempting v2 connection when P2P network activity is being turned off). vasild: ACK 6869fb4 Tree-SHA512: 54f596e54c5a6546f2c3fec2609aa8d10dec3adcf1001ca16666d8b374b8d79d64397f46c90d9b3915b4e91a5041b6ced3044fd2a5b4fb4aa7282eb51f61296a
2 parents b3162d1 + 6869fb4 commit a0d737c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,8 @@ void CConnman::DisconnectNodes()
19121912
{
19131913
LOCK(m_nodes_mutex);
19141914

1915-
if (!fNetworkActive) {
1915+
const bool network_active{fNetworkActive};
1916+
if (!network_active) {
19161917
// Disconnect any connected nodes
19171918
for (CNode* pnode : m_nodes) {
19181919
if (!pnode->fDisconnect) {
@@ -1934,7 +1935,7 @@ void CConnman::DisconnectNodes()
19341935
// Add to reconnection list if appropriate. We don't reconnect right here, because
19351936
// the creation of a connection is a blocking operation (up to several seconds),
19361937
// and we don't want to hold up the socket handler thread for that long.
1937-
if (pnode->m_transport->ShouldReconnectV1()) {
1938+
if (network_active && pnode->m_transport->ShouldReconnectV1()) {
19381939
reconnections_to_add.push_back({
19391940
.addr_connect = pnode->addr,
19401941
.grant = std::move(pnode->grantOutbound),

0 commit comments

Comments
 (0)