diff options
author | Carl Dong <contact@carldong.me> | 2022-03-07 21:32:12 -0500 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-03-15 19:40:51 -0400 |
commit | 42e56d9b188f97c077ed2269e24acc0be35ece17 (patch) | |
tree | 4c7d7d7190ccce87481bec65c42ffd1cabe2b04d /src/node/blockstorage.cpp | |
parent | 3bbb6fea051f4e19bd2448e401a6c4e9b4cc7a41 (diff) |
style-only: No need for std::pair for vSortedByHeight
...since the height information in already in CBlockIndex* and we can
use an easy custom sorter.
Diffstat (limited to 'src/node/blockstorage.cpp')
-rw-r--r-- | src/node/blockstorage.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index f948a6cbd7..29ad8285ec 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -220,17 +220,20 @@ bool BlockManager::LoadBlockIndex( } // Calculate nChainWork - std::vector<std::pair<int, CBlockIndex*>> vSortedByHeight; + std::vector<CBlockIndex*> vSortedByHeight; vSortedByHeight.reserve(m_block_index.size()); for (auto& [_, block_index] : m_block_index) { - vSortedByHeight.push_back(std::make_pair(block_index.nHeight, &block_index)); + vSortedByHeight.push_back(&block_index); } - sort(vSortedByHeight.begin(), vSortedByHeight.end()); + sort(vSortedByHeight.begin(), vSortedByHeight.end(), + [](const CBlockIndex* pa, const CBlockIndex* pb) { + return pa->nHeight < pb->nHeight; + }); // Find start of assumed-valid region. int first_assumed_valid_height = std::numeric_limits<int>::max(); - for (const auto& [height, block] : vSortedByHeight) { + for (const CBlockIndex* block : vSortedByHeight) { if (block->IsAssumedValid()) { auto chainstates = chainman.GetAll(); @@ -242,14 +245,13 @@ bool BlockManager::LoadBlockIndex( assert(any_chain([](auto chainstate) { return chainstate->reliesOnAssumedValid(); })); assert(any_chain([](auto chainstate) { return !chainstate->reliesOnAssumedValid(); })); - first_assumed_valid_height = height; + first_assumed_valid_height = block->nHeight; break; } } - for (const std::pair<int, CBlockIndex*>& item : vSortedByHeight) { + for (CBlockIndex* pindex : vSortedByHeight) { if (ShutdownRequested()) return false; - CBlockIndex* pindex = item.second; pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex); pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime); |