@@ -1856,9 +1856,9 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
18561856{
18571857 AssertLockHeld (cs_main);
18581858 if (m_chainman.ActiveChain ().Contains (pindex)) return true ;
1859- return pindex->IsValid (BLOCK_VALID_SCRIPTS) && (pindexBestHeader != nullptr ) &&
1860- (pindexBestHeader ->GetBlockTime () - pindex->GetBlockTime () < STALE_RELAY_AGE_LIMIT) &&
1861- (GetBlockProofEquivalentTime (*pindexBestHeader , *pindex, *pindexBestHeader , m_chainparams.GetConsensus ()) < STALE_RELAY_AGE_LIMIT);
1859+ return pindex->IsValid (BLOCK_VALID_SCRIPTS) && (m_chainman. m_best_header != nullptr ) &&
1860+ (m_chainman. m_best_header ->GetBlockTime () - pindex->GetBlockTime () < STALE_RELAY_AGE_LIMIT) &&
1861+ (GetBlockProofEquivalentTime (*m_chainman. m_best_header , *pindex, *m_chainman. m_best_header , m_chainparams.GetConsensus ()) < STALE_RELAY_AGE_LIMIT);
18621862}
18631863
18641864std::optional<std::string> PeerManagerImpl::FetchBlock (NodeId peer_id, const CBlockIndex& block_index)
@@ -2434,7 +2434,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
24342434 const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
24352435 // disconnect node in case we have reached the outbound limit for serving historical blocks
24362436 if (m_connman.OutboundTargetReached (true ) &&
2437- (((pindexBestHeader != nullptr ) && (pindexBestHeader ->GetBlockTime () - pindex->GetBlockTime () > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk ()) &&
2437+ (((m_chainman. m_best_header != nullptr ) && (m_chainman. m_best_header ->GetBlockTime () - pindex->GetBlockTime () > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk ()) &&
24382438 !pfrom.HasPermission (NetPermissionFlags::Download) // nodes with the download permission may exceed target
24392439 ) {
24402440 LogPrint (BCLog::NET, " historical block serving limit reached, disconnect peer=%d\n " , pfrom.GetId ());
@@ -2824,13 +2824,13 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
28242824 if (!m_chainman.m_blockman .LookupBlockIndex (headers[0 ].hashPrevBlock ) && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
28252825 nodestate->nUnconnectingHeaders ++;
28262826 std::string msg_type = (pfrom.nServices & NODE_HEADERS_COMPRESSED) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS;
2827- m_connman.PushMessage (&pfrom, msgMaker.Make (msg_type, m_chainman.ActiveChain ().GetLocator (pindexBestHeader ), uint256 ()));
2827+ m_connman.PushMessage (&pfrom, msgMaker.Make (msg_type, m_chainman.ActiveChain ().GetLocator (m_chainman. m_best_header ), uint256 ()));
28282828 LogPrint (BCLog::NET, " received header %s: missing prev block %s, sending %s (%d) to end (peer=%d, nUnconnectingHeaders=%d)\n " ,
2829- headers[0 ].GetHash ().ToString (),
2830- headers[0 ].hashPrevBlock .ToString (),
2831- msg_type,
2832- pindexBestHeader ->nHeight ,
2833- pfrom.GetId (), nodestate->nUnconnectingHeaders );
2829+ headers[0 ].GetHash ().ToString (),
2830+ headers[0 ].hashPrevBlock .ToString (),
2831+ msg_type,
2832+ m_chainman. m_best_header ->nHeight ,
2833+ pfrom.GetId (), nodestate->nUnconnectingHeaders );
28342834 // Set hashLastUnknownBlock for this peer, so that if we
28352835 // eventually get the headers - even from a different peer -
28362836 // we can use this peer to download.
@@ -2887,7 +2887,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
28872887
28882888 if (nCount == MAX_HEADERS_RESULTS) {
28892889 // Headers message had its maximum size; the peer may have more headers.
2890- // TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or pindexBestHeader , continue
2890+ // TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or m_chainman.m_best_header , continue
28912891 // from there instead.
28922892 std::string msg_type = (pfrom.nServices & NODE_HEADERS_COMPRESSED) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS;
28932893 LogPrint (BCLog::NET, " more %s (%d) to end to peer=%d (startheight:%d)\n " ,
@@ -3819,15 +3819,15 @@ void PeerManagerImpl::ProcessMessage(
38193819 // Download if this is a nice peer, or we have no nice peers and this one might do.
38203820 bool fFetch = state->fPreferredDownload || (nPreferredDownload == 0 && !pfrom.IsAddrFetchConn ());
38213821 // Only actively request headers from a single peer, unless we're close to end of initial download.
3822- if ((nSyncStarted == 0 && fFetch ) || pindexBestHeader ->GetBlockTime () > GetAdjustedTime () - nMaxTipAge) {
3822+ if ((nSyncStarted == 0 && fFetch ) || m_chainman. m_best_header ->GetBlockTime () > GetAdjustedTime () - nMaxTipAge) {
38233823 // Make sure to mark this peer as the one we are currently syncing with etc.
38243824 state->fSyncStarted = true ;
38253825 state->m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
38263826 (
38273827 // Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
38283828 // to maintain precision
38293829 std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
3830- (GetAdjustedTime () - pindexBestHeader ->GetBlockTime ()) / m_chainparams.GetConsensus ().nPowTargetSpacing
3830+ (GetAdjustedTime () - m_chainman. m_best_header ->GetBlockTime ()) / m_chainparams.GetConsensus ().nPowTargetSpacing
38313831 );
38323832 nSyncStarted++;
38333833 // Headers-first is the primary method of announcement on
@@ -3872,8 +3872,8 @@ void PeerManagerImpl::ProcessMessage(
38723872 }
38733873 if (best_block != nullptr ) {
38743874 std::string msg_type = (pfrom.nServices & NODE_HEADERS_COMPRESSED) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS;
3875- m_connman.PushMessage (&pfrom, msgMaker.Make (msg_type, m_chainman.ActiveChain ().GetLocator (pindexBestHeader ), *best_block));
3876- LogPrint (BCLog::NET, " %s (%d) %s to peer=%d\n " , msg_type, pindexBestHeader ->nHeight , best_block->ToString (), pfrom.GetId ());
3875+ m_connman.PushMessage (&pfrom, msgMaker.Make (msg_type, m_chainman.ActiveChain ().GetLocator (m_chainman. m_best_header ), *best_block));
3876+ LogPrint (BCLog::NET, " %s (%d) %s to peer=%d\n " , msg_type, m_chainman. m_best_header ->nHeight , best_block->ToString (), pfrom.GetId ());
38773877 }
38783878
38793879 return ;
@@ -4289,7 +4289,7 @@ void PeerManagerImpl::ProcessMessage(
42894289 if (!m_chainman.m_blockman .LookupBlockIndex (cmpctblock.header .hashPrevBlock )) {
42904290 // Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
42914291 if (!m_chainman.ActiveChainstate ().IsInitialBlockDownload ())
4292- m_connman.PushMessage (&pfrom, msgMaker.Make ((pfrom.nServices & NODE_HEADERS_COMPRESSED) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (pindexBestHeader ), uint256 ()));
4292+ m_connman.PushMessage (&pfrom, msgMaker.Make ((pfrom.nServices & NODE_HEADERS_COMPRESSED) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (m_chainman. m_best_header ), uint256 ()));
42934293 return ;
42944294 }
42954295
@@ -5445,28 +5445,29 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
54455445 CNodeState &state = *State (pto->GetId ());
54465446
54475447 // Start block sync
5448- if (pindexBestHeader == nullptr )
5449- pindexBestHeader = m_chainman.ActiveChain ().Tip ();
5448+ if (m_chainman.m_best_header == nullptr ) {
5449+ m_chainman.m_best_header = m_chainman.ActiveChain ().Tip ();
5450+ }
54505451 bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn ()); // Download if this is a nice peer, or we have no nice peers and this one might do.
54515452 if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->CanRelay ()) {
54525453 // Only actively request headers from a single peer, unless we're close to end of initial download.
5453- if ((nSyncStarted == 0 && fFetch ) || pindexBestHeader ->GetBlockTime () > GetAdjustedTime () - nMaxTipAge) {
5454+ if ((nSyncStarted == 0 && fFetch ) || m_chainman. m_best_header ->GetBlockTime () > GetAdjustedTime () - nMaxTipAge) {
54545455 state.fSyncStarted = true ;
54555456 state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
54565457 (
54575458 // Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
54585459 // to maintain precision
54595460 std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
5460- (GetAdjustedTime () - pindexBestHeader ->GetBlockTime ()) / consensusParams.nPowTargetSpacing
5461+ (GetAdjustedTime () - m_chainman. m_best_header ->GetBlockTime ()) / consensusParams.nPowTargetSpacing
54615462 );
54625463 nSyncStarted++;
5463- const CBlockIndex * pindexStart = pindexBestHeader ;
5464+ const CBlockIndex* pindexStart = m_chainman. m_best_header ;
54645465 /* If possible, start at the block preceding the currently
54655466 best known header. This ensures that we always get a
54665467 non-empty list of headers back as long as the peer
54675468 is up-to-date. With a non-empty response, we can initialise
54685469 the peer's known best block. This wouldn't be possible
5469- if we requested starting at pindexBestHeader and
5470+ if we requested starting at m_chainman.m_best_header and
54705471 got back an empty response. */
54715472 if (pindexStart->pprev )
54725473 pindexStart = pindexStart->pprev ;
@@ -5835,7 +5836,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58355836 // Check for headers sync timeouts
58365837 if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max ()) {
58375838 // Detect whether this is a stalling initial-headers-sync peer
5838- if (pindexBestHeader ->GetBlockTime () <= GetAdjustedTime () - nMaxTipAge) {
5839+ if (m_chainman. m_best_header ->GetBlockTime () <= GetAdjustedTime () - nMaxTipAge) {
58395840 if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1 )) {
58405841 // Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
58415842 // and we have others we could be using instead.
0 commit comments