From 3463a7f4813c3eece5ba9a260670a76e3f8d38ab Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 12 Mar 2025 20:47:49 -0600 Subject: [PATCH] p2p: don't disconnect addnode peers for block download timeout --- src/net_processing.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 1986d1b8be0..c8d2ee5b3b9 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -5803,7 +5803,8 @@ bool PeerManagerImpl::SendMessages(CNode* pto) return true; } // In case there is a block that has been in flight from this peer for block_interval * (1 + 0.5 * N) - // (with N the number of peers from which we're downloading validated blocks), disconnect due to timeout. + // (with N the number of peers from which we're downloading validated blocks), disconnect due to timeout + // unless it is an addnode peer. // We compensate for other peers to prevent killing off peers due to our own downstream link // being saturated. We only count validated in-flight blocks so peers can't advertise non-existing block hashes // to unreasonably increase our timeout. @@ -5811,8 +5812,12 @@ bool PeerManagerImpl::SendMessages(CNode* pto) QueuedBlock &queuedBlock = state.vBlocksInFlight.front(); int nOtherPeersWithValidatedDownloads = m_peers_downloading_from - 1; if (current_time > state.m_downloading_since + std::chrono::seconds{consensusParams.nPowTargetSpacing} * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) { - LogInfo("Timeout downloading block %s, %s\n", queuedBlock.pindex->GetBlockHash().ToString(), pto->DisconnectMsg(fLogIPs)); - pto->fDisconnect = true; + if (pto->IsManualConn()) { + LogInfo("Timeout downloading block %s from addnode peer, not %s\n", queuedBlock.pindex->GetBlockHash().ToString(), pto->DisconnectMsg(fLogIPs)); + } else { + LogInfo("Timeout downloading block %s, %s\n", queuedBlock.pindex->GetBlockHash().ToString(), pto->DisconnectMsg(fLogIPs)); + pto->fDisconnect = true; + } return true; } }