diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3146,15 +3146,12 @@ // The resulting new best tip may not be in setBlockIndexCandidates anymore, // so add it again. - BlockMap::iterator it = mapBlockIndex.begin(); - while (it != mapBlockIndex.end()) { - if (it->second->IsValid(BlockValidity::TRANSACTIONS) && - it->second->nChainTx && - !setBlockIndexCandidates.value_comp()(it->second, - chainActive.Tip())) { - setBlockIndexCandidates.insert(it->second); + for (const std::pair &it : mapBlockIndex) { + CBlockIndex *i = it.second; + if (i->IsValid(BlockValidity::TRANSACTIONS) && i->nChainTx && + !setBlockIndexCandidates.value_comp()(i, chainActive.Tip())) { + setBlockIndexCandidates.insert(i); } - it++; } InvalidChainFound(pindex);