@@ -388,6 +388,9 @@ struct Peer {
388
388
/* * Length of current-streak of unconnecting headers announcements */
389
389
int nUnconnectingHeaders GUARDED_BY (NetEventsInterface::g_msgproc_mutex){0 };
390
390
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
+
391
394
explicit Peer (NodeId id, ServiceFlags our_services)
392
395
: m_id{id}
393
396
, m_our_services{our_services}
@@ -419,8 +422,6 @@ struct CNodeState {
419
422
const CBlockIndex* pindexBestHeaderSent{nullptr };
420
423
// ! Whether we've started headers synchronization with this peer.
421
424
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};
424
425
// ! Since when we're stalling block download progress (in microseconds), or 0.
425
426
std::chrono::microseconds m_stalling_since{0us};
426
427
std::list<QueuedBlock> vBlocksInFlight;
@@ -5428,7 +5429,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5428
5429
LogPrint (BCLog::NET, " initial getheaders (%d) to peer=%d (startheight:%d)\n " , pindexStart->nHeight , pto->GetId (), peer->m_starting_height );
5429
5430
5430
5431
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 +
5432
5433
(
5433
5434
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
5434
5435
// to maintain precision
@@ -5755,10 +5756,10 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5755
5756
}
5756
5757
}
5757
5758
// 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 ()) {
5759
5760
// Detect whether this is a stalling initial-headers-sync peer
5760
5761
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 )) {
5762
5763
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
5763
5764
// and we have others we could be using instead.
5764
5765
// Note: If all our peers are inbound, then we won't
@@ -5777,13 +5778,13 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5777
5778
// this peer (eventually).
5778
5779
state.fSyncStarted = false ;
5779
5780
nSyncStarted--;
5780
- state. m_headers_sync_timeout = 0us;
5781
+ peer-> m_headers_sync_timeout = 0us;
5781
5782
}
5782
5783
}
5783
5784
} else {
5784
5785
// After we've caught up once, reset the timeout so we can't trigger
5785
5786
// disconnect later.
5786
- state. m_headers_sync_timeout = std::chrono::microseconds::max ();
5787
+ peer-> m_headers_sync_timeout = std::chrono::microseconds::max ();
5787
5788
}
5788
5789
}
5789
5790
0 commit comments