Skip to content

Commit 4b84e50

Browse files
committed
[net processing] Move m_headers_sync_timeout from CNodeState to Peer
1 parent 689b747 commit 4b84e50

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/net_processing.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ struct Peer {
388388
/** Length of current-streak of unconnecting headers announcements */
389389
int nUnconnectingHeaders GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0};
390390

391+
/** When to potentially disconnect peer for stalling headers download */
392+
std::chrono::microseconds m_headers_sync_timeout GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0us};
393+
391394
explicit Peer(NodeId id, ServiceFlags our_services)
392395
: m_id{id}
393396
, m_our_services{our_services}
@@ -419,8 +422,6 @@ struct CNodeState {
419422
const CBlockIndex* pindexBestHeaderSent{nullptr};
420423
//! Whether we've started headers synchronization with this peer.
421424
bool fSyncStarted{false};
422-
//! When to potentially disconnect peer for stalling headers download
423-
std::chrono::microseconds m_headers_sync_timeout GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0us};
424425
//! Since when we're stalling block download progress (in microseconds), or 0.
425426
std::chrono::microseconds m_stalling_since{0us};
426427
std::list<QueuedBlock> vBlocksInFlight;
@@ -5428,7 +5429,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
54285429
LogPrint(BCLog::NET, "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->GetId(), peer->m_starting_height);
54295430

54305431
state.fSyncStarted = true;
5431-
state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
5432+
peer->m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
54325433
(
54335434
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
54345435
// to maintain precision
@@ -5755,10 +5756,10 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
57555756
}
57565757
}
57575758
// Check for headers sync timeouts
5758-
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max()) {
5759+
if (state.fSyncStarted && peer->m_headers_sync_timeout < std::chrono::microseconds::max()) {
57595760
// Detect whether this is a stalling initial-headers-sync peer
57605761
if (m_chainman.m_best_header->Time() <= GetAdjustedTime() - 24h) {
5761-
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) {
5762+
if (current_time > peer->m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) {
57625763
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
57635764
// and we have others we could be using instead.
57645765
// Note: If all our peers are inbound, then we won't
@@ -5777,13 +5778,13 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
57775778
// this peer (eventually).
57785779
state.fSyncStarted = false;
57795780
nSyncStarted--;
5780-
state.m_headers_sync_timeout = 0us;
5781+
peer->m_headers_sync_timeout = 0us;
57815782
}
57825783
}
57835784
} else {
57845785
// After we've caught up once, reset the timeout so we can't trigger
57855786
// disconnect later.
5786-
state.m_headers_sync_timeout = std::chrono::microseconds::max();
5787+
peer->m_headers_sync_timeout = std::chrono::microseconds::max();
57875788
}
57885789
}
57895790

0 commit comments

Comments
 (0)