@@ -101,7 +101,7 @@ namespace {
101
101
/* * Blocks that are in flight, and that are in the queue to be downloaded. Protected by cs_main. */
102
102
struct QueuedBlock {
103
103
uint256 hash;
104
- CBlockIndex* pindex; // !< Optional.
104
+ const CBlockIndex* pindex; // !< Optional.
105
105
bool fValidatedHeaders ; // !< Whether this block has validated headers at the time of request.
106
106
std::unique_ptr<PartiallyDownloadedBlock> partialBlock; // !< Optional, used for CMPCTBLOCK downloads
107
107
};
@@ -156,13 +156,13 @@ struct CNodeState {
156
156
// ! List of asynchronously-determined block rejections to notify this peer about.
157
157
std::vector<CBlockReject> rejects;
158
158
// ! The best known block we know this peer has announced.
159
- CBlockIndex *pindexBestKnownBlock;
159
+ const CBlockIndex *pindexBestKnownBlock;
160
160
// ! The hash of the last unknown block this peer has announced.
161
161
uint256 hashLastUnknownBlock;
162
162
// ! The last full block we both have.
163
- CBlockIndex *pindexLastCommonBlock;
163
+ const CBlockIndex *pindexLastCommonBlock;
164
164
// ! The best header we have sent our peer.
165
- CBlockIndex *pindexBestHeaderSent;
165
+ const CBlockIndex *pindexBestHeaderSent;
166
166
// ! Length of current-streak of unconnecting headers announcements
167
167
int nUnconnectingHeaders;
168
168
// ! Whether we've started headers synchronization with this peer.
@@ -331,7 +331,7 @@ bool MarkBlockAsReceived(const uint256& hash) {
331
331
// Requires cs_main.
332
332
// returns false, still setting pit, if the block was already in flight from the same peer
333
333
// pit will only be valid as long as the same cs_main lock is being held
334
- bool MarkBlockAsInFlight (NodeId nodeid, const uint256& hash, const Consensus::Params& consensusParams, CBlockIndex *pindex = NULL , list<QueuedBlock>::iterator **pit = NULL ) {
334
+ bool MarkBlockAsInFlight (NodeId nodeid, const uint256& hash, const Consensus::Params& consensusParams, const CBlockIndex *pindex = NULL , list<QueuedBlock>::iterator **pit = NULL ) {
335
335
CNodeState *state = State (nodeid);
336
336
assert (state != NULL );
337
337
@@ -432,7 +432,7 @@ bool CanDirectFetch(const Consensus::Params &consensusParams)
432
432
}
433
433
434
434
// Requires cs_main
435
- bool PeerHasHeader (CNodeState *state, CBlockIndex *pindex)
435
+ bool PeerHasHeader (CNodeState *state, const CBlockIndex *pindex)
436
436
{
437
437
if (state->pindexBestKnownBlock && pindex == state->pindexBestKnownBlock ->GetAncestor (pindex->nHeight ))
438
438
return true ;
@@ -443,7 +443,7 @@ bool PeerHasHeader(CNodeState *state, CBlockIndex *pindex)
443
443
444
444
/* * Find the last common ancestor two blocks have.
445
445
* Both pa and pb must be non-NULL. */
446
- CBlockIndex* LastCommonAncestor (CBlockIndex* pa, CBlockIndex* pb) {
446
+ const CBlockIndex* LastCommonAncestor (const CBlockIndex* pa, const CBlockIndex* pb) {
447
447
if (pa->nHeight > pb->nHeight ) {
448
448
pa = pa->GetAncestor (pb->nHeight );
449
449
} else if (pb->nHeight > pa->nHeight ) {
@@ -462,7 +462,7 @@ CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb) {
462
462
463
463
/* * Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
464
464
* at most count entries. */
465
- void FindNextBlocksToDownload (NodeId nodeid, unsigned int count, std::vector<CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) {
465
+ void FindNextBlocksToDownload (NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) {
466
466
if (count == 0 )
467
467
return ;
468
468
@@ -490,8 +490,8 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl
490
490
if (state->pindexLastCommonBlock == state->pindexBestKnownBlock )
491
491
return ;
492
492
493
- std::vector<CBlockIndex*> vToFetch;
494
- CBlockIndex *pindexWalk = state->pindexLastCommonBlock ;
493
+ std::vector<const CBlockIndex*> vToFetch;
494
+ const CBlockIndex *pindexWalk = state->pindexLastCommonBlock ;
495
495
// Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last
496
496
// linked block we have in common with this peer. The +1 is so we can detect stalling, namely if we would be able to
497
497
// download that next block if the window were 1 larger.
@@ -514,7 +514,7 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl
514
514
// are not yet downloaded and not in flight to vBlocks. In the mean time, update
515
515
// pindexLastCommonBlock as long as all ancestors are already downloaded, or if it's
516
516
// already part of our chain (and therefore don't need it even if pruned).
517
- BOOST_FOREACH (CBlockIndex* pindex, vToFetch) {
517
+ BOOST_FOREACH (const CBlockIndex* pindex, vToFetch) {
518
518
if (!pindex->IsValid (BLOCK_VALID_TREE)) {
519
519
// We consider the chain that this peer is on invalid.
520
520
return ;
@@ -1049,7 +1049,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
1049
1049
}
1050
1050
}
1051
1051
1052
- uint32_t GetFetchFlags (CNode* pfrom, CBlockIndex* pprev, const Consensus::Params& chainparams) {
1052
+ uint32_t GetFetchFlags (CNode* pfrom, const CBlockIndex* pprev, const Consensus::Params& chainparams) {
1053
1053
uint32_t nFetchFlags = 0 ;
1054
1054
if ((pfrom->GetLocalServices () & NODE_WITNESS) && State (pfrom->GetId ())->fHaveWitness ) {
1055
1055
nFetchFlags |= MSG_WITNESS_FLAG;
@@ -1456,7 +1456,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1456
1456
LOCK (cs_main);
1457
1457
1458
1458
// Find the last block the caller has in the main chain
1459
- CBlockIndex* pindex = FindForkInGlobalIndex (chainActive, locator);
1459
+ const CBlockIndex* pindex = FindForkInGlobalIndex (chainActive, locator);
1460
1460
1461
1461
// Send the rest of the chain
1462
1462
if (pindex)
@@ -1552,7 +1552,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1552
1552
}
1553
1553
1554
1554
CNodeState *nodestate = State (pfrom->GetId ());
1555
- CBlockIndex* pindex = NULL ;
1555
+ const CBlockIndex* pindex = NULL ;
1556
1556
if (locator.IsNull ())
1557
1557
{
1558
1558
// If locator is null, return the hashStop block
@@ -1775,7 +1775,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1775
1775
}
1776
1776
}
1777
1777
1778
- CBlockIndex *pindex = NULL ;
1778
+ const CBlockIndex *pindex = NULL ;
1779
1779
CValidationState state;
1780
1780
if (!ProcessNewBlockHeaders ({cmpctblock.header }, state, chainparams, &pindex)) {
1781
1781
int nDoS;
@@ -2051,7 +2051,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
2051
2051
return true ;
2052
2052
}
2053
2053
2054
- CBlockIndex *pindexLast = NULL ;
2054
+ const CBlockIndex *pindexLast = NULL ;
2055
2055
{
2056
2056
LOCK (cs_main);
2057
2057
CNodeState *nodestate = State (pfrom->GetId ());
@@ -2128,8 +2128,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
2128
2128
// If this set of headers is valid and ends in a block with at least as
2129
2129
// much work as our tip, download as much as possible.
2130
2130
if (fCanDirectFetch && pindexLast->IsValid (BLOCK_VALID_TREE) && chainActive.Tip ()->nChainWork <= pindexLast->nChainWork ) {
2131
- vector<CBlockIndex *> vToFetch;
2132
- CBlockIndex *pindexWalk = pindexLast;
2131
+ vector<const CBlockIndex *> vToFetch;
2132
+ const CBlockIndex *pindexWalk = pindexLast;
2133
2133
// Calculate all the blocks we'd need to switch to pindexLast, up to a limit.
2134
2134
while (pindexWalk && !chainActive.Contains (pindexWalk) && vToFetch.size () <= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
2135
2135
if (!(pindexWalk->nStatus & BLOCK_HAVE_DATA) &&
@@ -2151,7 +2151,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
2151
2151
} else {
2152
2152
vector<CInv> vGetData;
2153
2153
// Download as much as possible, from earliest to latest.
2154
- BOOST_REVERSE_FOREACH (CBlockIndex *pindex, vToFetch) {
2154
+ BOOST_REVERSE_FOREACH (const CBlockIndex *pindex, vToFetch) {
2155
2155
if (nodestate->nBlocksInFlight >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
2156
2156
// Can't download any more from this peer
2157
2157
break ;
@@ -2740,7 +2740,7 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
2740
2740
bool fRevertToInv = ((!state.fPreferHeaders &&
2741
2741
(!state.fPreferHeaderAndIDs || pto->vBlockHashesToAnnounce .size () > 1 )) ||
2742
2742
pto->vBlockHashesToAnnounce .size () > MAX_BLOCKS_TO_ANNOUNCE);
2743
- CBlockIndex *pBestIndex = NULL ; // last header queued for delivery
2743
+ const CBlockIndex *pBestIndex = NULL ; // last header queued for delivery
2744
2744
ProcessBlockAvailability (pto->id ); // ensure pindexBestKnownBlock is up-to-date
2745
2745
2746
2746
if (!fRevertToInv ) {
@@ -2751,7 +2751,7 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
2751
2751
BOOST_FOREACH (const uint256 &hash, pto->vBlockHashesToAnnounce ) {
2752
2752
BlockMap::iterator mi = mapBlockIndex.find (hash);
2753
2753
assert (mi != mapBlockIndex.end ());
2754
- CBlockIndex *pindex = mi->second ;
2754
+ const CBlockIndex *pindex = mi->second ;
2755
2755
if (chainActive[pindex->nHeight ] != pindex) {
2756
2756
// Bail out if we reorged away from this block
2757
2757
fRevertToInv = true ;
@@ -2828,7 +2828,7 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
2828
2828
const uint256 &hashToAnnounce = pto->vBlockHashesToAnnounce .back ();
2829
2829
BlockMap::iterator mi = mapBlockIndex.find (hashToAnnounce);
2830
2830
assert (mi != mapBlockIndex.end ());
2831
- CBlockIndex *pindex = mi->second ;
2831
+ const CBlockIndex *pindex = mi->second ;
2832
2832
2833
2833
// Warn if we're announcing a block that is not on the main chain.
2834
2834
// This should be very rare and could be optimized out.
@@ -3013,10 +3013,10 @@ bool SendMessages(CNode* pto, CConnman& connman, std::atomic<bool>& interruptMsg
3013
3013
//
3014
3014
vector<CInv> vGetData;
3015
3015
if (!pto->fClient && (fFetch || !IsInitialBlockDownload ()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
3016
- vector<CBlockIndex*> vToDownload;
3016
+ vector<const CBlockIndex*> vToDownload;
3017
3017
NodeId staller = -1 ;
3018
3018
FindNextBlocksToDownload (pto->GetId (), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight , vToDownload, staller, consensusParams);
3019
- BOOST_FOREACH (CBlockIndex *pindex, vToDownload) {
3019
+ BOOST_FOREACH (const CBlockIndex *pindex, vToDownload) {
3020
3020
uint32_t nFetchFlags = GetFetchFlags (pto, pindex->pprev , consensusParams);
3021
3021
vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
3022
3022
MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), consensusParams, pindex);
0 commit comments