@@ -1856,9 +1856,9 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
1856
1856
{
1857
1857
AssertLockHeld (cs_main);
1858
1858
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);
1862
1862
}
1863
1863
1864
1864
std::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&
2434
2434
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
2435
2435
// disconnect node in case we have reached the outbound limit for serving historical blocks
2436
2436
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 ()) &&
2438
2438
!pfrom.HasPermission (NetPermissionFlags::Download) // nodes with the download permission may exceed target
2439
2439
) {
2440
2440
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,
2824
2824
if (!m_chainman.m_blockman .LookupBlockIndex (headers[0 ].hashPrevBlock ) && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
2825
2825
nodestate->nUnconnectingHeaders ++;
2826
2826
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 ()));
2828
2828
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 );
2834
2834
// Set hashLastUnknownBlock for this peer, so that if we
2835
2835
// eventually get the headers - even from a different peer -
2836
2836
// we can use this peer to download.
@@ -2887,7 +2887,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
2887
2887
2888
2888
if (nCount == MAX_HEADERS_RESULTS) {
2889
2889
// 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
2891
2891
// from there instead.
2892
2892
std::string msg_type = (pfrom.nServices & NODE_HEADERS_COMPRESSED) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS;
2893
2893
LogPrint (BCLog::NET, " more %s (%d) to end to peer=%d (startheight:%d)\n " ,
@@ -3819,15 +3819,15 @@ void PeerManagerImpl::ProcessMessage(
3819
3819
// Download if this is a nice peer, or we have no nice peers and this one might do.
3820
3820
bool fFetch = state->fPreferredDownload || (nPreferredDownload == 0 && !pfrom.IsAddrFetchConn ());
3821
3821
// 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) {
3823
3823
// Make sure to mark this peer as the one we are currently syncing with etc.
3824
3824
state->fSyncStarted = true ;
3825
3825
state->m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
3826
3826
(
3827
3827
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
3828
3828
// to maintain precision
3829
3829
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
3831
3831
);
3832
3832
nSyncStarted++;
3833
3833
// Headers-first is the primary method of announcement on
@@ -3872,8 +3872,8 @@ void PeerManagerImpl::ProcessMessage(
3872
3872
}
3873
3873
if (best_block != nullptr ) {
3874
3874
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 ());
3877
3877
}
3878
3878
3879
3879
return ;
@@ -4289,7 +4289,7 @@ void PeerManagerImpl::ProcessMessage(
4289
4289
if (!m_chainman.m_blockman .LookupBlockIndex (cmpctblock.header .hashPrevBlock )) {
4290
4290
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
4291
4291
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 ()));
4293
4293
return ;
4294
4294
}
4295
4295
@@ -5445,28 +5445,29 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5445
5445
CNodeState &state = *State (pto->GetId ());
5446
5446
5447
5447
// 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
+ }
5450
5451
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.
5451
5452
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->CanRelay ()) {
5452
5453
// 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) {
5454
5455
state.fSyncStarted = true ;
5455
5456
state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
5456
5457
(
5457
5458
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
5458
5459
// to maintain precision
5459
5460
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
5460
- (GetAdjustedTime () - pindexBestHeader ->GetBlockTime ()) / consensusParams.nPowTargetSpacing
5461
+ (GetAdjustedTime () - m_chainman. m_best_header ->GetBlockTime ()) / consensusParams.nPowTargetSpacing
5461
5462
);
5462
5463
nSyncStarted++;
5463
- const CBlockIndex * pindexStart = pindexBestHeader ;
5464
+ const CBlockIndex* pindexStart = m_chainman. m_best_header ;
5464
5465
/* If possible, start at the block preceding the currently
5465
5466
best known header. This ensures that we always get a
5466
5467
non-empty list of headers back as long as the peer
5467
5468
is up-to-date. With a non-empty response, we can initialise
5468
5469
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
5470
5471
got back an empty response. */
5471
5472
if (pindexStart->pprev )
5472
5473
pindexStart = pindexStart->pprev ;
@@ -5835,7 +5836,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5835
5836
// Check for headers sync timeouts
5836
5837
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max ()) {
5837
5838
// 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) {
5839
5840
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1 )) {
5840
5841
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
5841
5842
// and we have others we could be using instead.
0 commit comments