@@ -1978,7 +1978,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
1978
1978
// effectively caching the result of part of the verification.
1979
1979
BlockMap::const_iterator it = m_blockman.m_block_index .find (hashAssumeValid);
1980
1980
if (it != m_blockman.m_block_index .end ()) {
1981
- if (it->second -> GetAncestor (pindex->nHeight ) == pindex &&
1981
+ if (it->second . GetAncestor (pindex->nHeight ) == pindex &&
1982
1982
pindexBestHeader->GetAncestor (pindex->nHeight ) == pindex &&
1983
1983
pindexBestHeader->nChainWork >= nMinimumChainWork) {
1984
1984
// This block is a member of the assumed verified chain and an ancestor of the best header.
@@ -3035,8 +3035,8 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
3035
3035
3036
3036
{
3037
3037
LOCK (cs_main);
3038
- for (const auto & entry : m_blockman.m_block_index ) {
3039
- CBlockIndex * candidate = entry.second ;
3038
+ for (auto & entry : m_blockman.m_block_index ) {
3039
+ CBlockIndex* candidate = & entry.second ;
3040
3040
// We don't need to put anything in our active chain into the
3041
3041
// multimap, because those candidates will be found and considered
3042
3042
// as we disconnect.
@@ -3133,12 +3133,10 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
3133
3133
// it up here, this should be an essentially unobservable error.
3134
3134
// Loop back over all block index entries and add any missing entries
3135
3135
// to setBlockIndexCandidates.
3136
- BlockMap::iterator it = m_blockman.m_block_index .begin ();
3137
- while (it != m_blockman.m_block_index .end ()) {
3138
- if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && it->second ->HaveTxsDownloaded () && !setBlockIndexCandidates.value_comp ()(it->second , m_chain.Tip ())) {
3139
- setBlockIndexCandidates.insert (it->second );
3136
+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
3137
+ if (block_index.IsValid (BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded () && !setBlockIndexCandidates.value_comp ()(&block_index, m_chain.Tip ())) {
3138
+ setBlockIndexCandidates.insert (&block_index);
3140
3139
}
3141
- it++;
3142
3140
}
3143
3141
3144
3142
InvalidChainFound (to_mark_failed);
@@ -3157,21 +3155,19 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
3157
3155
int nHeight = pindex->nHeight ;
3158
3156
3159
3157
// Remove the invalidity flag from this block and all its descendants.
3160
- BlockMap::iterator it = m_blockman.m_block_index .begin ();
3161
- while (it != m_blockman.m_block_index .end ()) {
3162
- if (!it->second ->IsValid () && it->second ->GetAncestor (nHeight) == pindex) {
3163
- it->second ->nStatus &= ~BLOCK_FAILED_MASK;
3164
- m_blockman.m_dirty_blockindex .insert (it->second );
3165
- if (it->second ->IsValid (BLOCK_VALID_TRANSACTIONS) && it->second ->HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), it->second )) {
3166
- setBlockIndexCandidates.insert (it->second );
3158
+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
3159
+ if (!block_index.IsValid () && block_index.GetAncestor (nHeight) == pindex) {
3160
+ block_index.nStatus &= ~BLOCK_FAILED_MASK;
3161
+ m_blockman.m_dirty_blockindex .insert (&block_index);
3162
+ if (block_index.IsValid (BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded () && setBlockIndexCandidates.value_comp ()(m_chain.Tip (), &block_index)) {
3163
+ setBlockIndexCandidates.insert (&block_index);
3167
3164
}
3168
- if (it-> second == m_chainman.m_best_invalid ) {
3165
+ if (&block_index == m_chainman.m_best_invalid ) {
3169
3166
// Reset invalid block marker if it was pointing to one of those.
3170
3167
m_chainman.m_best_invalid = nullptr ;
3171
3168
}
3172
- m_chainman.m_failed_blocks .erase (it-> second );
3169
+ m_chainman.m_failed_blocks .erase (&block_index );
3173
3170
}
3174
- it++;
3175
3171
}
3176
3172
3177
3173
// Remove the invalidity flag from all ancestors too.
@@ -3500,7 +3496,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
3500
3496
if (hash != chainparams.GetConsensus ().hashGenesisBlock ) {
3501
3497
if (miSelf != m_blockman.m_block_index .end ()) {
3502
3498
// Block header is already known.
3503
- CBlockIndex* pindex = miSelf->second ;
3499
+ CBlockIndex* pindex = &( miSelf->second ) ;
3504
3500
if (ppindex)
3505
3501
*ppindex = pindex;
3506
3502
if (pindex->nStatus & BLOCK_FAILED_MASK) {
@@ -3522,7 +3518,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
3522
3518
LogPrint (BCLog::VALIDATION, " %s: %s prev block not found\n " , __func__, hash.ToString ());
3523
3519
return state.Invalid (BlockValidationResult::BLOCK_MISSING_PREV, " prev-blk-not-found" );
3524
3520
}
3525
- pindexPrev = ( *mi).second ;
3521
+ pindexPrev = &(( *mi).second ) ;
3526
3522
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) {
3527
3523
LogPrint (BCLog::VALIDATION, " %s: %s prev block invalid\n " , __func__, hash.ToString ());
3528
3524
return state.Invalid (BlockValidationResult::BLOCK_INVALID_PREV, " bad-prevblk" );
@@ -3994,13 +3990,13 @@ bool CChainState::ReplayBlocks()
3994
3990
if (m_blockman.m_block_index .count (hashHeads[0 ]) == 0 ) {
3995
3991
return error (" ReplayBlocks(): reorganization to unknown block requested" );
3996
3992
}
3997
- pindexNew = m_blockman.m_block_index [hashHeads[0 ]];
3993
+ pindexNew = &( m_blockman.m_block_index [hashHeads[0 ]]) ;
3998
3994
3999
3995
if (!hashHeads[1 ].IsNull ()) { // The old tip is allowed to be 0, indicating it's the first flush.
4000
3996
if (m_blockman.m_block_index .count (hashHeads[1 ]) == 0 ) {
4001
3997
return error (" ReplayBlocks(): reorganization from unknown block requested" );
4002
3998
}
4003
- pindexOld = m_blockman.m_block_index [hashHeads[1 ]];
3999
+ pindexOld = &( m_blockman.m_block_index [hashHeads[1 ]]) ;
4004
4000
pindexFork = LastCommonAncestor (pindexOld, pindexNew);
4005
4001
assert (pindexFork != nullptr );
4006
4002
}
@@ -4267,8 +4263,8 @@ void CChainState::CheckBlockIndex()
4267
4263
4268
4264
// Build forward-pointing map of the entire block tree.
4269
4265
std::multimap<CBlockIndex*,CBlockIndex*> forward;
4270
- for (const std::pair< const uint256, CBlockIndex*>& entry : m_blockman.m_block_index ) {
4271
- forward.insert ( std::make_pair (entry. second -> pprev , entry. second ) );
4266
+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
4267
+ forward.emplace (block_index. pprev , &block_index );
4272
4268
}
4273
4269
4274
4270
assert (forward.size () == m_blockman.m_block_index .size ());
0 commit comments