Add and use CBlockIndexHeightOnlyComparator

...also use std::sort for clarity
This commit is contained in:
Carl Dong
2022-03-15 19:19:58 -04:00
parent 12eb05df63
commit 28ba0313ea
3 changed files with 20 additions and 13 deletions

View File

@@ -47,6 +47,11 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIn
return false;
}
bool CBlockIndexHeightOnlyComparator::operator()(const CBlockIndex* pa, const CBlockIndex* pb) const
{
return pa->nHeight < pb->nHeight;
}
static FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false);
static FlatFileSeq BlockFileSeq();
static FlatFileSeq UndoFileSeq();
@@ -242,10 +247,8 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
for (auto& [_, block_index] : m_block_index) {
vSortedByHeight.push_back(&block_index);
}
sort(vSortedByHeight.begin(), vSortedByHeight.end(),
[](const CBlockIndex* pa, const CBlockIndex* pb) {
return pa->nHeight < pb->nHeight;
});
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
CBlockIndexHeightOnlyComparator());
for (CBlockIndex* pindex : vSortedByHeight) {
if (ShutdownRequested()) return false;