@@ -312,10 +312,10 @@ void ProcessBlockAvailability(NodeId nodeid)
312312 assert (state != nullptr );
313313
314314 if (!state->hashLastUnknownBlock .IsNull ()) {
315- BlockMap::iterator itOld = mapBlockIndex. find (state->hashLastUnknownBlock );
316- if (itOld != mapBlockIndex. end () && itOld-> second ->nChainWork > 0 ) {
317- if (state->pindexBestKnownBlock == NULL || itOld-> second ->nChainWork >= state->pindexBestKnownBlock ->nChainWork )
318- state->pindexBestKnownBlock = itOld-> second ;
315+ CBlockIndex* pindex = LookupBlockIndex (state->hashLastUnknownBlock );
316+ if (pindex && pindex ->nChainWork > 0 ) {
317+ if (state->pindexBestKnownBlock == NULL || pindex ->nChainWork >= state->pindexBestKnownBlock ->nChainWork )
318+ state->pindexBestKnownBlock = pindex ;
319319 state->hashLastUnknownBlock .SetNull ();
320320 }
321321 }
@@ -329,11 +329,11 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256& hash)
329329
330330 ProcessBlockAvailability (nodeid);
331331
332- BlockMap::iterator it = mapBlockIndex. find (hash);
333- if (it != mapBlockIndex. end () && it-> second ->nChainWork > 0 ) {
332+ CBlockIndex* pindex = LookupBlockIndex (hash);
333+ if (pindex && pindex ->nChainWork > 0 ) {
334334 // An actually better block was announced.
335- if (state->pindexBestKnownBlock == NULL || it-> second ->nChainWork >= state->pindexBestKnownBlock ->nChainWork )
336- state->pindexBestKnownBlock = it-> second ;
335+ if (state->pindexBestKnownBlock == NULL || pindex ->nChainWork >= state->pindexBestKnownBlock ->nChainWork )
336+ state->pindexBestKnownBlock = pindex ;
337337 } else {
338338 // An unknown block was announced; just assume that the latest one is the best one.
339339 state->hashLastUnknownBlock = hash;
@@ -625,9 +625,9 @@ static void CheckBlockSpam(NodeId nodeId, const uint256& hashBlock)
625625 nodestate = State (nodeId);
626626 if (!nodestate) { return ; }
627627
628- const auto it = mapBlockIndex. find (hashBlock);
629- if (it == mapBlockIndex. end () ) { return ; }
630- blockReceivedHeight = it-> second ->nHeight ;
628+ CBlockIndex* pindex = LookupBlockIndex (hashBlock);
629+ if (!pindex ) { return ; }
630+ blockReceivedHeight = pindex ->nHeight ;
631631 }
632632
633633 nodestate->nodeBlocks .onBlockReceived (blockReceivedHeight);
@@ -766,7 +766,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
766766 }
767767
768768 case MSG_BLOCK:
769- return mapBlockIndex. count (inv.hash );
769+ return LookupBlockIndex (inv.hash ) != nullptr ;
770770 case MSG_TXLOCK_REQUEST:
771771 // deprecated
772772 return true ;
@@ -956,26 +956,26 @@ void static ProcessGetBlockData(CNode* pfrom, const CInv& inv, CConnman* connman
956956 CNetMsgMaker msgMaker (pfrom->GetSendVersion ());
957957
958958 bool send = false ;
959- BlockMap::iterator mi = mapBlockIndex. find (inv.hash );
960- if (mi != mapBlockIndex. end () ) {
961- if (chainActive.Contains (mi-> second )) {
959+ CBlockIndex* pindex = LookupBlockIndex (inv.hash );
960+ if (pindex ) {
961+ if (chainActive.Contains (pindex )) {
962962 send = true ;
963963 } else {
964964 // To prevent fingerprinting attacks, only send blocks outside of the active
965965 // chain if they are valid, and no more than a max reorg depth than the best header
966966 // chain we know about.
967- send = mi-> second ->IsValid (BLOCK_VALID_SCRIPTS) && (pindexBestHeader != NULL ) &&
968- (chainActive.Height () - mi-> second ->nHeight < gArgs .GetArg (" -maxreorg" , DEFAULT_MAX_REORG_DEPTH));
967+ send = pindex ->IsValid (BLOCK_VALID_SCRIPTS) && (pindexBestHeader != NULL ) &&
968+ (chainActive.Height () - pindex ->nHeight < gArgs .GetArg (" -maxreorg" , DEFAULT_MAX_REORG_DEPTH));
969969 if (!send) {
970970 LogPrint (BCLog::NET, " ProcessGetData(): ignoring request from peer=%i for old block that isn't in the main chain\n " , pfrom->GetId ());
971971 }
972972 }
973973 }
974974 // Don't send not-validated blocks
975- if (send && (mi-> second ->nStatus & BLOCK_HAVE_DATA)) {
975+ if (send && (pindex ->nStatus & BLOCK_HAVE_DATA)) {
976976 // Send block from disk
977977 CBlock block;
978- if (!ReadBlockFromDisk (block, (*mi). second ))
978+ if (!ReadBlockFromDisk (block, pindex ))
979979 assert (!" cannot load block from disk" );
980980 if (inv.type == MSG_BLOCK)
981981 connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::BLOCK, block));
@@ -1512,10 +1512,9 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
15121512 CBlockIndex* pindex = NULL ;
15131513 if (locator.IsNull ()) {
15141514 // If locator is null, return the hashStop block
1515- BlockMap::iterator mi = mapBlockIndex. find (hashStop);
1516- if (mi == mapBlockIndex. end () )
1515+ CBlockIndex* pindex = LookupBlockIndex (hashStop);
1516+ if (!pindex )
15171517 return true ;
1518- pindex = (*mi).second ;
15191518 } else {
15201519 // Find the last block the caller has in the main chain
15211520 pindex = FindForkInGlobalIndex (chainActive, locator);
0 commit comments