@@ -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.
@@ -4261,8 +4257,8 @@ void CChainState::CheckBlockIndex()
4261
4257
4262
4258
// Build forward-pointing map of the entire block tree.
4263
4259
std::multimap<CBlockIndex*,CBlockIndex*> forward;
4264
- for (std::pair< const uint256, CBlockIndex>& entry : m_blockman.m_block_index ) {
4265
- forward.insert ( std::make_pair (entry. second . pprev , &entry. second ) );
4260
+ for (auto & [_, block_index] : m_blockman.m_block_index ) {
4261
+ forward.emplace (block_index. pprev , &block_index );
4266
4262
}
4267
4263
4268
4264
assert (forward.size () == m_blockman.m_block_index .size ());
0 commit comments