mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
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.
This commit is contained in:
parent
3bbb6fea05
commit
42e56d9b18
1 changed files with 9 additions and 7 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue