@@ -657,9 +657,9 @@ class PeerManagerImpl final : public PeerManager
657
657
*/
658
658
bool MaybeSendGetHeaders (CNode& pfrom, const CBlockLocator& locator, Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
659
659
/* * Potentially fetch blocks from this peer upon receipt of a new headers tip */
660
- void HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex* pindexLast );
660
+ void HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex& last_header );
661
661
/* * Update peer state based on received headers message */
662
- void UpdatePeerStateForReceivedHeaders (CNode& pfrom, const CBlockIndex *pindexLast , bool received_new_header, bool may_have_more_headers);
662
+ void UpdatePeerStateForReceivedHeaders (CNode& pfrom, const CBlockIndex& last_header , bool received_new_header, bool may_have_more_headers);
663
663
664
664
void SendBlockTransactions (CNode& pfrom, Peer& peer, const CBlock& block, const BlockTransactionsRequest& req);
665
665
@@ -2605,22 +2605,21 @@ bool PeerManagerImpl::MaybeSendGetHeaders(CNode& pfrom, const CBlockLocator& loc
2605
2605
}
2606
2606
2607
2607
/*
2608
- * Given a new headers tip ending in pindexLast , potentially request blocks towards that tip.
2608
+ * Given a new headers tip ending in last_header , potentially request blocks towards that tip.
2609
2609
* We require that the given tip have at least as much work as our tip, and for
2610
2610
* our current tip to be "close to synced" (see CanDirectFetch()).
2611
2611
*/
2612
- void PeerManagerImpl::HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex* pindexLast )
2612
+ void PeerManagerImpl::HeadersDirectFetchBlocks (CNode& pfrom, const Peer& peer, const CBlockIndex& last_header )
2613
2613
{
2614
2614
const CNetMsgMaker msgMaker (pfrom.GetCommonVersion ());
2615
2615
2616
2616
LOCK (cs_main);
2617
2617
CNodeState *nodestate = State (pfrom.GetId ());
2618
2618
2619
- if (CanDirectFetch () && pindexLast->IsValid (BLOCK_VALID_TREE) && m_chainman.ActiveChain ().Tip ()->nChainWork <= pindexLast->nChainWork ) {
2620
-
2619
+ if (CanDirectFetch () && last_header.IsValid (BLOCK_VALID_TREE) && m_chainman.ActiveChain ().Tip ()->nChainWork <= last_header.nChainWork ) {
2621
2620
std::vector<const CBlockIndex*> vToFetch;
2622
- const CBlockIndex *pindexWalk = pindexLast ;
2623
- // Calculate all the blocks we'd need to switch to pindexLast , up to a limit.
2621
+ const CBlockIndex* pindexWalk{&last_header} ;
2622
+ // Calculate all the blocks we'd need to switch to last_header , up to a limit.
2624
2623
while (pindexWalk && !m_chainman.ActiveChain ().Contains (pindexWalk) && vToFetch.size () <= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
2625
2624
if (!(pindexWalk->nStatus & BLOCK_HAVE_DATA) &&
2626
2625
!IsBlockRequested (pindexWalk->GetBlockHash ()) &&
@@ -2636,8 +2635,8 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2636
2635
// direct fetch and rely on parallel download instead.
2637
2636
if (!m_chainman.ActiveChain ().Contains (pindexWalk)) {
2638
2637
LogPrint (BCLog::NET, " Large reorg, won't direct fetch to %s (%d)\n " ,
2639
- pindexLast-> GetBlockHash ().ToString (),
2640
- pindexLast-> nHeight );
2638
+ last_header. GetBlockHash ().ToString (),
2639
+ last_header. nHeight );
2641
2640
} else {
2642
2641
std::vector<CInv> vGetData;
2643
2642
// Download as much as possible, from earliest to latest.
@@ -2654,14 +2653,15 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2654
2653
}
2655
2654
if (vGetData.size () > 1 ) {
2656
2655
LogPrint (BCLog::NET, " Downloading blocks toward %s (%d) via headers direct fetch\n " ,
2657
- pindexLast->GetBlockHash ().ToString (), pindexLast->nHeight );
2656
+ last_header.GetBlockHash ().ToString (),
2657
+ last_header.nHeight );
2658
2658
}
2659
2659
if (vGetData.size () > 0 ) {
2660
2660
if (!m_ignore_incoming_txs &&
2661
2661
nodestate->m_provides_cmpctblocks &&
2662
2662
vGetData.size () == 1 &&
2663
2663
mapBlocksInFlight.size () == 1 &&
2664
- pindexLast-> pprev ->IsValid (BLOCK_VALID_CHAIN)) {
2664
+ last_header. pprev ->IsValid (BLOCK_VALID_CHAIN)) {
2665
2665
// In any case, we want to download using a compact block, not a regular one
2666
2666
vGetData[0 ] = CInv (MSG_CMPCT_BLOCK, vGetData[0 ].hash );
2667
2667
}
@@ -2672,12 +2672,12 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2672
2672
}
2673
2673
2674
2674
/* *
2675
- * Given receipt of headers from a peer ending in pindexLast , along with
2675
+ * Given receipt of headers from a peer ending in last_header , along with
2676
2676
* whether that header was new and whether the headers message was full,
2677
2677
* update the state we keep for the peer.
2678
2678
*/
2679
2679
void PeerManagerImpl::UpdatePeerStateForReceivedHeaders (CNode& pfrom,
2680
- const CBlockIndex *pindexLast , bool received_new_header, bool may_have_more_headers)
2680
+ const CBlockIndex& last_header , bool received_new_header, bool may_have_more_headers)
2681
2681
{
2682
2682
LOCK (cs_main);
2683
2683
CNodeState *nodestate = State (pfrom.GetId ());
@@ -2686,14 +2686,13 @@ void PeerManagerImpl::UpdatePeerStateForReceivedHeaders(CNode& pfrom,
2686
2686
}
2687
2687
nodestate->nUnconnectingHeaders = 0 ;
2688
2688
2689
- assert (pindexLast);
2690
- UpdateBlockAvailability (pfrom.GetId (), pindexLast->GetBlockHash ());
2689
+ UpdateBlockAvailability (pfrom.GetId (), last_header.GetBlockHash ());
2691
2690
2692
2691
// From here, pindexBestKnownBlock should be guaranteed to be non-null,
2693
2692
// because it is set in UpdateBlockAvailability. Some nullptr checks
2694
2693
// are still present, however, as belt-and-suspenders.
2695
2694
2696
- if (received_new_header && pindexLast-> nChainWork > m_chainman.ActiveChain ().Tip ()->nChainWork ) {
2695
+ if (received_new_header && last_header. nChainWork > m_chainman.ActiveChain ().Tip ()->nChainWork ) {
2697
2696
nodestate->m_last_block_announcement = GetTime ();
2698
2697
}
2699
2698
@@ -2859,7 +2858,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
2859
2858
return ;
2860
2859
}
2861
2860
}
2862
- Assume (pindexLast);
2861
+ assert (pindexLast);
2863
2862
2864
2863
// Consider fetching more headers if we are not using our headers-sync mechanism.
2865
2864
if (nCount == MAX_HEADERS_RESULTS && !have_headers_sync) {
@@ -2870,10 +2869,10 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
2870
2869
}
2871
2870
}
2872
2871
2873
- UpdatePeerStateForReceivedHeaders (pfrom, pindexLast, received_new_header, nCount == MAX_HEADERS_RESULTS);
2872
+ UpdatePeerStateForReceivedHeaders (pfrom, * pindexLast, received_new_header, nCount == MAX_HEADERS_RESULTS);
2874
2873
2875
2874
// Consider immediately downloading blocks.
2876
- HeadersDirectFetchBlocks (pfrom, peer, pindexLast);
2875
+ HeadersDirectFetchBlocks (pfrom, peer, * pindexLast);
2877
2876
2878
2877
return ;
2879
2878
}
0 commit comments