@@ -1906,7 +1906,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
19061906 // effectively caching the result of part of the verification.
19071907 BlockMap::const_iterator it = m_blockman.m_block_index .find (hashAssumeValid);
19081908 if (it != m_blockman.m_block_index .end ()) {
1909- if (it->second -> GetAncestor (pindex->nHeight ) == pindex &&
1909+ if (it->second . GetAncestor (pindex->nHeight ) == pindex &&
19101910 pindexBestHeader->GetAncestor (pindex->nHeight ) == pindex &&
19111911 pindexBestHeader->nChainWork >= nMinimumChainWork) {
19121912 // This block is a member of the assumed verified chain and an ancestor of the best header.
@@ -3116,8 +3116,8 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
31163116
31173117 {
31183118 LOCK (cs_main);
3119- for (const auto & entry : m_blockman.m_block_index ) {
3120- CBlockIndex * candidate = entry.second ;
3119+ for (auto & entry : m_blockman.m_block_index ) {
3120+ CBlockIndex* candidate = & entry.second ;
31213121 // We don't need to put anything in our active chain into the
31223122 // multimap, because those candidates will be found and considered
31233123 // as we disconnect.
@@ -3225,12 +3225,10 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
32253225 // it up here, this should be an essentially unobservable error.
32263226 // Loop back over all block index entries and add any missing entries
32273227 // to setBlockIndexCandidates.
3228- BlockMap::iterator it = m_blockman.m_block_index .begin ();
3229- while (it != m_blockman.m_block_index .end ()) {
3230- if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && !(it->second ->nStatus & BLOCK_CONFLICT_CHAINLOCK) && it->second ->HaveTxsDownloaded () && !setBlockIndexCandidates.value_comp ()(it->second , m_chain.Tip ())) {
3231- setBlockIndexCandidates.insert (it->second );
3228+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
3229+ if (block_index.IsValid (BLOCK_VALID_TRANSACTIONS) && !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK) && block_index.HaveTxsDownloaded () && !setBlockIndexCandidates.value_comp ()(&block_index, m_chain.Tip ())) {
3230+ setBlockIndexCandidates.insert (&block_index);
32323231 }
3233- it++;
32343232 }
32353233
32363234 InvalidChainFound (to_mark_failed);
@@ -3329,8 +3327,8 @@ bool CChainState::MarkConflictingBlock(BlockValidationState& state, CBlockIndex
33293327 // add it again.
33303328 BlockMap::iterator it = m_blockman.m_block_index .begin ();
33313329 while (it != m_blockman.m_block_index .end ()) {
3332- if (it->second -> IsValid (BLOCK_VALID_TRANSACTIONS) && !(it->second -> nStatus & BLOCK_CONFLICT_CHAINLOCK) && it->second -> HaveTxsDownloaded () && !setBlockIndexCandidates.value_comp ()(it->second , m_chain.Tip ())) {
3333- setBlockIndexCandidates.insert (it->second );
3330+ if (it->second . IsValid (BLOCK_VALID_TRANSACTIONS) && !(it->second . nStatus & BLOCK_CONFLICT_CHAINLOCK) && it->second . HaveTxsDownloaded () && !setBlockIndexCandidates.value_comp ()(& it->second , m_chain.Tip ())) {
3331+ setBlockIndexCandidates.insert (& it->second );
33343332 }
33353333 it++;
33363334 }
@@ -3362,21 +3360,19 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
33623360 int nHeight = pindex->nHeight ;
33633361
33643362 // Remove the invalidity flag from this block and all its descendants.
3365- BlockMap::iterator it = m_blockman.m_block_index .begin ();
3366- while (it != m_blockman.m_block_index .end ()) {
3367- if (!it->second ->IsValid () && it->second ->GetAncestor (nHeight) == pindex) {
3368- it->second ->nStatus &= ~BLOCK_FAILED_MASK;
3369- m_blockman.m_dirty_blockindex .insert (it->second );
3370- if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && !(it->second ->nStatus & BLOCK_CONFLICT_CHAINLOCK) && it->second ->HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), it->second )) {
3371- setBlockIndexCandidates.insert (it->second );
3363+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
3364+ if (!block_index.IsValid () && block_index.GetAncestor (nHeight) == pindex) {
3365+ block_index.nStatus &= ~BLOCK_FAILED_MASK;
3366+ m_blockman.m_dirty_blockindex .insert (&block_index);
3367+ if (block_index.IsValid (BLOCK_VALID_TRANSACTIONS) && !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK) && block_index.HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), &block_index)) {
3368+ setBlockIndexCandidates.insert (&block_index);
33723369 }
3373- if (it-> second == m_chainman.m_best_invalid ) {
3370+ if (&block_index == m_chainman.m_best_invalid ) {
33743371 // Reset invalid block marker if it was pointing to one of those.
33753372 m_chainman.m_best_invalid = nullptr ;
33763373 }
3377- m_chainman.m_failed_blocks .erase (it-> second );
3374+ m_chainman.m_failed_blocks .erase (&block_index );
33783375 }
3379- it++;
33803376 }
33813377
33823378 // Remove the invalidity flag from all ancestors too.
@@ -3687,7 +3683,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
36873683 if (hash != chainparams.GetConsensus ().hashGenesisBlock ) {
36883684 if (miSelf != m_blockman.m_block_index .end ()) {
36893685 // Block header is already known.
3690- CBlockIndex* pindex = miSelf->second ;
3686+ CBlockIndex* pindex = &( miSelf->second ) ;
36913687 if (ppindex)
36923688 *ppindex = pindex;
36933689 if (pindex->nStatus & BLOCK_FAILED_MASK) {
@@ -3713,7 +3709,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
37133709 LogPrintf (" ERROR: %s: prev block not found\n " , __func__);
37143710 return state.Invalid (BlockValidationResult::BLOCK_MISSING_PREV, " prev-blk-not-found" );
37153711 }
3716- pindexPrev = ( *mi).second ;
3712+ pindexPrev = &(( *mi).second ) ;
37173713 assert (pindexPrev);
37183714
37193715 if (pindexPrev->nStatus & BLOCK_FAILED_MASK) {
@@ -4298,13 +4294,13 @@ bool CChainState::ReplayBlocks()
42984294 if (m_blockman.m_block_index .count (hashHeads[0 ]) == 0 ) {
42994295 return error (" ReplayBlocks(): reorganization to unknown block requested" );
43004296 }
4301- pindexNew = m_blockman.m_block_index [hashHeads[0 ]];
4297+ pindexNew = &( m_blockman.m_block_index [hashHeads[0 ]]) ;
43024298
43034299 if (!hashHeads[1 ].IsNull ()) { // The old tip is allowed to be 0, indicating it's the first flush.
43044300 if (m_blockman.m_block_index .count (hashHeads[1 ]) == 0 ) {
43054301 return error (" ReplayBlocks(): reorganization from unknown block requested" );
43064302 }
4307- pindexOld = m_blockman.m_block_index [hashHeads[1 ]];
4303+ pindexOld = &( m_blockman.m_block_index [hashHeads[1 ]]) ;
43084304 pindexFork = LastCommonAncestor (pindexOld, pindexNew);
43094305 assert (pindexFork != nullptr );
43104306 const bool fDIP0003Active = pindexOld->nHeight >= m_params.GetConsensus ().DIP0003Height ;
@@ -4590,8 +4586,8 @@ void CChainState::CheckBlockIndex()
45904586
45914587 // Build forward-pointing map of the entire block tree.
45924588 std::multimap<CBlockIndex*,CBlockIndex*> forward;
4593- for (const std::pair< const uint256, CBlockIndex*>& entry : m_blockman.m_block_index ) {
4594- forward.insert ( std::make_pair (entry. second -> pprev , entry. second ) );
4589+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
4590+ forward.emplace (block_index. pprev , &block_index );
45954591 }
45964592
45974593 assert (forward.size () == m_blockman.m_block_index .size ());
0 commit comments