mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-22 06:43:25 +02: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
@ -220,17 +220,20 @@ bool BlockManager::LoadBlockIndex(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate nChainWork
|
// Calculate nChainWork
|
||||||
std::vector<std::pair<int, CBlockIndex*>> vSortedByHeight;
|
std::vector<CBlockIndex*> vSortedByHeight;
|
||||||
vSortedByHeight.reserve(m_block_index.size());
|
vSortedByHeight.reserve(m_block_index.size());
|
||||||
for (auto& [_, block_index] : m_block_index) {
|
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.
|
// Find start of assumed-valid region.
|
||||||
int first_assumed_valid_height = std::numeric_limits<int>::max();
|
int first_assumed_valid_height = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
for (const auto& [height, block] : vSortedByHeight) {
|
for (const CBlockIndex* block : vSortedByHeight) {
|
||||||
if (block->IsAssumedValid()) {
|
if (block->IsAssumedValid()) {
|
||||||
auto chainstates = chainman.GetAll();
|
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(); }));
|
||||||
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const std::pair<int, CBlockIndex*>& item : vSortedByHeight) {
|
for (CBlockIndex* pindex : vSortedByHeight) {
|
||||||
if (ShutdownRequested()) return false;
|
if (ShutdownRequested()) return false;
|
||||||
CBlockIndex* pindex = item.second;
|
|
||||||
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
|
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
|
||||||
pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime);
|
pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user