@@ -661,9 +661,9 @@ class PeerManagerImpl final : public PeerManager
661
661
*/
662
662
bool MaybeSendGetHeaders (CNode& pfrom, const CBlockLocator& locator, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
663
663
/* * Potentially fetch blocks from this peer upon receipt of a new headers tip */
664
- void HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex* pindexLast );
664
+ void HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex& last_header );
665
665
/* * Update peer state based on received headers message */
666
- void UpdatePeerStateForReceivedHeaders (CNode& pfrom, const CBlockIndex *pindexLast , bool received_new_header, bool may_have_more_headers);
666
+ void UpdatePeerStateForReceivedHeaders (CNode& pfrom, const CBlockIndex& last_header , bool received_new_header, bool may_have_more_headers);
667
667
668
668
void SendBlockTransactions (CNode& pfrom, Peer& peer, const CBlock& block, const BlockTransactionsRequest& req);
669
669
@@ -2622,22 +2622,21 @@ bool PeerManagerImpl::MaybeSendGetHeaders(CNode& pfrom, const CBlockLocator& loc
2622
2622
}
2623
2623
2624
2624
/*
2625
- * Given a new headers tip ending in pindexLast , potentially request blocks towards that tip.
2625
+ * Given a new headers tip ending in last_header , potentially request blocks towards that tip.
2626
2626
* We require that the given tip have at least as much work as our tip, and for
2627
2627
* our current tip to be "close to synced" (see CanDirectFetch()).
2628
2628
*/
2629
- void PeerManagerImpl::HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex* pindexLast )
2629
+ void PeerManagerImpl::HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex& last_header )
2630
2630
{
2631
2631
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
2632
2632
2633
2633
LOCK (cs_main);
2634
2634
CNodeState *nodestate = State (pfrom.GetId ());
2635
2635
2636
- if (CanDirectFetch () && pindexLast->IsValid (BLOCK_VALID_TREE) && m_chainman.ActiveChain ().Tip ()->nChainWork <= pindexLast->nChainWork ) {
2637
-
2636
+ if (CanDirectFetch () && last_header.IsValid (BLOCK_VALID_TREE) && m_chainman.ActiveChain ().Tip ()->nChainWork <= last_header.nChainWork ) {
2638
2637
std::vector<const CBlockIndex*> vToFetch;
2639
- const CBlockIndex *pindexWalk = pindexLast ;
2640
- // Calculate all the blocks we'd need to switch to pindexLast , up to a limit.
2638
+ const CBlockIndex* pindexWalk{&last_header} ;
2639
+ // Calculate all the blocks we'd need to switch to last_header , up to a limit.
2641
2640
while (pindexWalk && !m_chainman.ActiveChain ().Contains (pindexWalk) && vToFetch.size () <= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
2642
2641
if (!(pindexWalk->nStatus & BLOCK_HAVE_DATA) &&
2643
2642
!IsBlockRequested (pindexWalk->GetBlockHash ()) &&
@@ -2653,8 +2652,8 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2653
2652
// direct fetch and rely on parallel download instead.
2654
2653
if (!m_chainman.ActiveChain ().Contains (pindexWalk)) {
2655
2654
LogPrint (BCLog::NET, " Large reorg, won't direct fetch to %s (%d)\n " ,
2656
- pindexLast-> GetBlockHash ().ToString (),
2657
- pindexLast-> nHeight );
2655
+ last_header. GetBlockHash ().ToString (),
2656
+ last_header. nHeight );
2658
2657
} else {
2659
2658
std::vector<CInv> vGetData;
2660
2659
// Download as much as possible, from earliest to latest.
@@ -2671,14 +2670,15 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2671
2670
}
2672
2671
if (vGetData.size () > 1 ) {
2673
2672
LogPrint (BCLog::NET, " Downloading blocks toward %s (%d) via headers direct fetch\n " ,
2674
- pindexLast->GetBlockHash ().ToString (), pindexLast->nHeight );
2673
+ last_header.GetBlockHash ().ToString (),
2674
+ last_header.nHeight );
2675
2675
}
2676
2676
if (vGetData.size () > 0 ) {
2677
2677
if (!m_ignore_incoming_txs &&
2678
2678
nodestate->m_provides_cmpctblocks &&
2679
2679
vGetData.size () == 1 &&
2680
2680
mapBlocksInFlight.size () == 1 &&
2681
- pindexLast-> pprev ->IsValid (BLOCK_VALID_CHAIN)) {
2681
+ last_header. pprev ->IsValid (BLOCK_VALID_CHAIN)) {
2682
2682
// In any case, we want to download using a compact block, not a regular one
2683
2683
vGetData[0 ] = CInv (MSG_CMPCT_BLOCK, vGetData[0 ].hash );
2684
2684
}
@@ -2689,12 +2689,12 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2689
2689
}
2690
2690
2691
2691
/* *
2692
- * Given receipt of headers from a peer ending in pindexLast , along with
2692
+ * Given receipt of headers from a peer ending in last_header , along with
2693
2693
* whether that header was new and whether the headers message was full,
2694
2694
* update the state we keep for the peer.
2695
2695
*/
2696
2696
void PeerManagerImpl::UpdatePeerStateForReceivedHeaders (CNode& pfrom,
2697
- const CBlockIndex *pindexLast , bool received_new_header, bool may_have_more_headers)
2697
+ const CBlockIndex& last_header , bool received_new_header, bool may_have_more_headers)
2698
2698
{
2699
2699
LOCK (cs_main);
2700
2700
CNodeState *nodestate = State (pfrom.GetId ());
@@ -2703,14 +2703,13 @@ void PeerManagerImpl::UpdatePeerStateForReceivedHeaders(CNode& pfrom,
2703
2703
}
2704
2704
nodestate->nUnconnectingHeaders = 0 ;
2705
2705
2706
- assert (pindexLast);
2707
- UpdateBlockAvailability (pfrom.GetId (), pindexLast->GetBlockHash ());
2706
+ UpdateBlockAvailability (pfrom.GetId (), last_header.GetBlockHash ());
2708
2707
2709
2708
// From here, pindexBestKnownBlock should be guaranteed to be non-null,
2710
2709
// because it is set in UpdateBlockAvailability. Some nullptr checks
2711
2710
// are still present, however, as belt-and-suspenders.
2712
2711
2713
- if (received_new_header && pindexLast-> nChainWork > m_chainman.ActiveChain ().Tip ()->nChainWork ) {
2712
+ if (received_new_header && last_header. nChainWork > m_chainman.ActiveChain ().Tip ()->nChainWork ) {
2714
2713
nodestate->m_last_block_announcement = GetTime ();
2715
2714
}
2716
2715
@@ -2876,7 +2875,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
2876
2875
return ;
2877
2876
}
2878
2877
}
2879
- Assume (pindexLast);
2878
+ assert (pindexLast);
2880
2879
2881
2880
// Consider fetching more headers if we are not using our headers-sync mechanism.
2882
2881
if (nCount == MAX_HEADERS_RESULTS && !have_headers_sync) {
@@ -2887,10 +2886,10 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
2887
2886
}
2888
2887
}
2889
2888
2890
- UpdatePeerStateForReceivedHeaders (pfrom, pindexLast, received_new_header, nCount == MAX_HEADERS_RESULTS);
2889
+ UpdatePeerStateForReceivedHeaders (pfrom, * pindexLast, received_new_header, nCount == MAX_HEADERS_RESULTS);
2891
2890
2892
2891
// Consider immediately downloading blocks.
2893
- HeadersDirectFetchBlocks (pfrom, peer, pindexLast);
2892
+ HeadersDirectFetchBlocks (pfrom, peer, * pindexLast);
2894
2893
2895
2894
return ;
2896
2895
}
0 commit comments