@@ -220,17 +220,20 @@ bool BlockManager::LoadBlockIndex(
220
220
}
221
221
222
222
// Calculate nChainWork
223
- std::vector<std::pair< int , CBlockIndex*> > vSortedByHeight;
223
+ std::vector<CBlockIndex*> vSortedByHeight;
224
224
vSortedByHeight.reserve (m_block_index.size ());
225
225
for (auto & [_, block_index] : m_block_index) {
226
- vSortedByHeight.push_back (std::make_pair (block_index. nHeight , &block_index) );
226
+ vSortedByHeight.push_back (&block_index);
227
227
}
228
- sort (vSortedByHeight.begin (), vSortedByHeight.end ());
228
+ sort (vSortedByHeight.begin (), vSortedByHeight.end (),
229
+ [](const CBlockIndex* pa, const CBlockIndex* pb) {
230
+ return pa->nHeight < pb->nHeight ;
231
+ });
229
232
230
233
// Find start of assumed-valid region.
231
234
int first_assumed_valid_height = std::numeric_limits<int >::max ();
232
235
233
- for (const auto & [height, block] : vSortedByHeight) {
236
+ for (const CBlockIndex* block : vSortedByHeight) {
234
237
if (block->IsAssumedValid ()) {
235
238
auto chainstates = chainman.GetAll ();
236
239
@@ -242,14 +245,13 @@ bool BlockManager::LoadBlockIndex(
242
245
assert (any_chain ([](auto chainstate) { return chainstate->reliesOnAssumedValid (); }));
243
246
assert (any_chain ([](auto chainstate) { return !chainstate->reliesOnAssumedValid (); }));
244
247
245
- first_assumed_valid_height = height ;
248
+ first_assumed_valid_height = block-> nHeight ;
246
249
break ;
247
250
}
248
251
}
249
252
250
- for (const std::pair< int , CBlockIndex*>& item : vSortedByHeight) {
253
+ for (CBlockIndex* pindex : vSortedByHeight) {
251
254
if (ShutdownRequested ()) return false ;
252
- CBlockIndex* pindex = item.second ;
253
255
pindex->nChainWork = (pindex->pprev ? pindex->pprev ->nChainWork : 0 ) + GetBlockProof (*pindex);
254
256
pindex->nTimeMax = (pindex->pprev ? std::max (pindex->pprev ->nTimeMax , pindex->nTime ) : pindex->nTime );
255
257
0 commit comments