@@ -1499,9 +1499,9 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
1499
1499
{
1500
1500
AssertLockHeld (cs_main);
1501
1501
if (m_chainman.ActiveChain ().Contains (pindex)) return true ;
1502
- return pindex->IsValid (BLOCK_VALID_SCRIPTS) && (pindexBestHeader != nullptr ) &&
1503
- (pindexBestHeader ->GetBlockTime () - pindex->GetBlockTime () < STALE_RELAY_AGE_LIMIT) &&
1504
- (GetBlockProofEquivalentTime (*pindexBestHeader , *pindex, *pindexBestHeader , m_chainparams.GetConsensus ()) < STALE_RELAY_AGE_LIMIT);
1502
+ return pindex->IsValid (BLOCK_VALID_SCRIPTS) && (m_chainman. m_best_header != nullptr ) &&
1503
+ (m_chainman. m_best_header ->GetBlockTime () - pindex->GetBlockTime () < STALE_RELAY_AGE_LIMIT) &&
1504
+ (GetBlockProofEquivalentTime (*m_chainman. m_best_header , *pindex, *m_chainman. m_best_header , m_chainparams.GetConsensus ()) < STALE_RELAY_AGE_LIMIT);
1505
1505
}
1506
1506
1507
1507
std::optional<std::string> PeerManagerImpl::FetchBlock (NodeId peer_id, const CBlockIndex& block_index)
@@ -1896,7 +1896,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
1896
1896
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
1897
1897
// disconnect node in case we have reached the outbound limit for serving historical blocks
1898
1898
if (m_connman.OutboundTargetReached (true ) &&
1899
- (((pindexBestHeader != nullptr ) && (pindexBestHeader ->GetBlockTime () - pindex->GetBlockTime () > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk ()) &&
1899
+ (((m_chainman. m_best_header != nullptr ) && (m_chainman. m_best_header ->GetBlockTime () - pindex->GetBlockTime () > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk ()) &&
1900
1900
!pfrom.HasPermission (NetPermissionFlags::Download) // nodes with the download permission may exceed target
1901
1901
) {
1902
1902
LogPrint (BCLog::NET, " historical block serving limit reached, disconnect peer=%d\n " , pfrom.GetId ());
@@ -2173,12 +2173,12 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
2173
2173
// nUnconnectingHeaders gets reset back to 0.
2174
2174
if (!m_chainman.m_blockman .LookupBlockIndex (headers[0 ].hashPrevBlock ) && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
2175
2175
nodestate->nUnconnectingHeaders ++;
2176
- m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (pindexBestHeader ), uint256 ()));
2176
+ m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (m_chainman. m_best_header ), uint256 ()));
2177
2177
LogPrint (BCLog::NET, " received header %s: missing prev block %s, sending getheaders (%d) to end (peer=%d, nUnconnectingHeaders=%d)\n " ,
2178
- headers[0 ].GetHash ().ToString (),
2179
- headers[0 ].hashPrevBlock .ToString (),
2180
- pindexBestHeader ->nHeight ,
2181
- pfrom.GetId (), nodestate->nUnconnectingHeaders );
2178
+ headers[0 ].GetHash ().ToString (),
2179
+ headers[0 ].hashPrevBlock .ToString (),
2180
+ m_chainman. m_best_header ->nHeight ,
2181
+ pfrom.GetId (), nodestate->nUnconnectingHeaders );
2182
2182
// Set hashLastUnknownBlock for this peer, so that if we
2183
2183
// eventually get the headers - even from a different peer -
2184
2184
// we can use this peer to download.
@@ -2235,7 +2235,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
2235
2235
2236
2236
if (nCount == MAX_HEADERS_RESULTS) {
2237
2237
// Headers message had its maximum size; the peer may have more headers.
2238
- // TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or pindexBestHeader , continue
2238
+ // TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or m_chainman.m_best_header , continue
2239
2239
// from there instead.
2240
2240
LogPrint (BCLog::NET, " more getheaders (%d) to end to peer=%d (startheight:%d)\n " ,
2241
2241
pindexLast->nHeight , pfrom.GetId (), peer.m_starting_height );
@@ -3102,8 +3102,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3102
3102
}
3103
3103
3104
3104
if (best_block != nullptr ) {
3105
- m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (pindexBestHeader ), *best_block));
3106
- LogPrint (BCLog::NET, " getheaders (%d) %s to peer=%d\n " , pindexBestHeader ->nHeight , best_block->ToString (), pfrom.GetId ());
3105
+ m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (m_chainman. m_best_header ), *best_block));
3106
+ LogPrint (BCLog::NET, " getheaders (%d) %s to peer=%d\n " , m_chainman. m_best_header ->nHeight , best_block->ToString (), pfrom.GetId ());
3107
3107
}
3108
3108
3109
3109
return ;
@@ -3549,7 +3549,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3549
3549
if (!m_chainman.m_blockman .LookupBlockIndex (cmpctblock.header .hashPrevBlock )) {
3550
3550
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
3551
3551
if (!m_chainman.ActiveChainstate ().IsInitialBlockDownload ())
3552
- m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (pindexBestHeader ), uint256 ()));
3552
+ m_connman.PushMessage (&pfrom, msgMaker.Make (NetMsgType::GETHEADERS, m_chainman.ActiveChain ().GetLocator (m_chainman. m_best_header ), uint256 ()));
3553
3553
return ;
3554
3554
}
3555
3555
@@ -4670,28 +4670,29 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4670
4670
CNodeState &state = *State (pto->GetId ());
4671
4671
4672
4672
// Start block sync
4673
- if (pindexBestHeader == nullptr )
4674
- pindexBestHeader = m_chainman.ActiveChain ().Tip ();
4673
+ if (m_chainman.m_best_header == nullptr ) {
4674
+ m_chainman.m_best_header = m_chainman.ActiveChain ().Tip ();
4675
+ }
4675
4676
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.
4676
4677
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex ) {
4677
4678
// Only actively request headers from a single peer, unless we're close to today.
4678
- if ((nSyncStarted == 0 && fFetch ) || pindexBestHeader ->GetBlockTime () > GetAdjustedTime () - 24 * 60 * 60 ) {
4679
+ if ((nSyncStarted == 0 && fFetch ) || m_chainman. m_best_header ->GetBlockTime () > GetAdjustedTime () - 24 * 60 * 60 ) {
4679
4680
state.fSyncStarted = true ;
4680
4681
state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
4681
4682
(
4682
4683
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
4683
4684
// to maintain precision
4684
4685
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
4685
- (GetAdjustedTime () - pindexBestHeader ->GetBlockTime ()) / consensusParams.nPowTargetSpacing
4686
+ (GetAdjustedTime () - m_chainman. m_best_header ->GetBlockTime ()) / consensusParams.nPowTargetSpacing
4686
4687
);
4687
4688
nSyncStarted++;
4688
- const CBlockIndex * pindexStart = pindexBestHeader ;
4689
+ const CBlockIndex* pindexStart = m_chainman. m_best_header ;
4689
4690
/* If possible, start at the block preceding the currently
4690
4691
best known header. This ensures that we always get a
4691
4692
non-empty list of headers back as long as the peer
4692
4693
is up-to-date. With a non-empty response, we can initialise
4693
4694
the peer's known best block. This wouldn't be possible
4694
- if we requested starting at pindexBestHeader and
4695
+ if we requested starting at m_chainman.m_best_header and
4695
4696
got back an empty response. */
4696
4697
if (pindexStart->pprev )
4697
4698
pindexStart = pindexStart->pprev ;
@@ -5016,7 +5017,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5016
5017
// Check for headers sync timeouts
5017
5018
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max ()) {
5018
5019
// Detect whether this is a stalling initial-headers-sync peer
5019
- if (pindexBestHeader ->GetBlockTime () <= GetAdjustedTime () - 24 * 60 * 60 ) {
5020
+ if (m_chainman. m_best_header ->GetBlockTime () <= GetAdjustedTime () - 24 * 60 * 60 ) {
5020
5021
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1 )) {
5021
5022
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
5022
5023
// and we have others we could be using instead.
0 commit comments