mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-20 13:53:15 +02:00
Add and use CBlockIndexHeightOnlyComparator
...also use std::sort for clarity
This commit is contained in:
parent
12eb05df63
commit
28ba0313ea
@ -47,6 +47,11 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex* pa, const CBlockIn
|
|||||||
return false;
|
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 FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false);
|
||||||
static FlatFileSeq BlockFileSeq();
|
static FlatFileSeq BlockFileSeq();
|
||||||
static FlatFileSeq UndoFileSeq();
|
static FlatFileSeq UndoFileSeq();
|
||||||
@ -242,10 +247,8 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
|
|||||||
for (auto& [_, block_index] : m_block_index) {
|
for (auto& [_, block_index] : m_block_index) {
|
||||||
vSortedByHeight.push_back(&block_index);
|
vSortedByHeight.push_back(&block_index);
|
||||||
}
|
}
|
||||||
sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||||
[](const CBlockIndex* pa, const CBlockIndex* pb) {
|
CBlockIndexHeightOnlyComparator());
|
||||||
return pa->nHeight < pb->nHeight;
|
|
||||||
});
|
|
||||||
|
|
||||||
for (CBlockIndex* pindex : vSortedByHeight) {
|
for (CBlockIndex* pindex : vSortedByHeight) {
|
||||||
if (ShutdownRequested()) return false;
|
if (ShutdownRequested()) return false;
|
||||||
|
@ -62,6 +62,11 @@ struct CBlockIndexWorkComparator {
|
|||||||
bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const;
|
bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CBlockIndexHeightOnlyComparator {
|
||||||
|
/* Only compares the height of two block indices, doesn't try to tie-break */
|
||||||
|
bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintains a tree of blocks (stored in `m_block_index`) which is consulted
|
* Maintains a tree of blocks (stored in `m_block_index`) which is consulted
|
||||||
* to determine where the most-work tip is.
|
* to determine where the most-work tip is.
|
||||||
|
@ -65,21 +65,22 @@
|
|||||||
using node::BLOCKFILE_CHUNK_SIZE;
|
using node::BLOCKFILE_CHUNK_SIZE;
|
||||||
using node::BlockManager;
|
using node::BlockManager;
|
||||||
using node::BlockMap;
|
using node::BlockMap;
|
||||||
|
using node::CBlockIndexHeightOnlyComparator;
|
||||||
using node::CBlockIndexWorkComparator;
|
using node::CBlockIndexWorkComparator;
|
||||||
using node::CCoinsStats;
|
using node::CCoinsStats;
|
||||||
using node::CoinStatsHashType;
|
using node::CoinStatsHashType;
|
||||||
|
using node::fHavePruned;
|
||||||
|
using node::fImporting;
|
||||||
|
using node::fPruneMode;
|
||||||
|
using node::fReindex;
|
||||||
using node::GetUTXOStats;
|
using node::GetUTXOStats;
|
||||||
|
using node::nPruneTarget;
|
||||||
using node::OpenBlockFile;
|
using node::OpenBlockFile;
|
||||||
using node::ReadBlockFromDisk;
|
using node::ReadBlockFromDisk;
|
||||||
using node::SnapshotMetadata;
|
using node::SnapshotMetadata;
|
||||||
using node::UNDOFILE_CHUNK_SIZE;
|
using node::UNDOFILE_CHUNK_SIZE;
|
||||||
using node::UndoReadFromDisk;
|
using node::UndoReadFromDisk;
|
||||||
using node::UnlinkPrunedFiles;
|
using node::UnlinkPrunedFiles;
|
||||||
using node::fHavePruned;
|
|
||||||
using node::fImporting;
|
|
||||||
using node::fPruneMode;
|
|
||||||
using node::fReindex;
|
|
||||||
using node::nPruneTarget;
|
|
||||||
|
|
||||||
#define MICRO 0.000001
|
#define MICRO 0.000001
|
||||||
#define MILLI 0.001
|
#define MILLI 0.001
|
||||||
@ -4073,10 +4074,8 @@ bool ChainstateManager::LoadBlockIndex()
|
|||||||
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
||||||
vSortedByHeight.push_back(&block_index);
|
vSortedByHeight.push_back(&block_index);
|
||||||
}
|
}
|
||||||
sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||||
[](const CBlockIndex* pa, const CBlockIndex* pb) {
|
CBlockIndexHeightOnlyComparator());
|
||||||
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user