mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
Add and use BlockManager::GetAllBlockIndices
This commit is contained in:
parent
28ba0313ea
commit
f865cf8ded
3 changed files with 15 additions and 10 deletions
|
@ -56,6 +56,17 @@ static FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false);
|
|||
static FlatFileSeq BlockFileSeq();
|
||||
static FlatFileSeq UndoFileSeq();
|
||||
|
||||
std::vector<CBlockIndex*> BlockManager::GetAllBlockIndices()
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
std::vector<CBlockIndex*> rv;
|
||||
rv.reserve(m_block_index.size());
|
||||
for (auto& [_, block_index] : m_block_index) {
|
||||
rv.push_back(&block_index);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
CBlockIndex* BlockManager::LookupBlockIndex(const uint256& hash)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
@ -242,11 +253,7 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
|
|||
}
|
||||
|
||||
// Calculate nChainWork
|
||||
std::vector<CBlockIndex*> vSortedByHeight;
|
||||
vSortedByHeight.reserve(m_block_index.size());
|
||||
for (auto& [_, block_index] : m_block_index) {
|
||||
vSortedByHeight.push_back(&block_index);
|
||||
}
|
||||
std::vector<CBlockIndex*> vSortedByHeight{GetAllBlockIndices()};
|
||||
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||
CBlockIndexHeightOnlyComparator());
|
||||
|
||||
|
|
|
@ -123,6 +123,8 @@ private:
|
|||
public:
|
||||
BlockMap m_block_index GUARDED_BY(cs_main);
|
||||
|
||||
std::vector<CBlockIndex*> GetAllBlockIndices() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
/**
|
||||
* All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
|
||||
* Pruned nodes may have entries where B is missing data.
|
||||
|
|
|
@ -4069,11 +4069,7 @@ bool ChainstateManager::LoadBlockIndex()
|
|||
bool ret = m_blockman.LoadBlockIndexDB();
|
||||
if (!ret) return false;
|
||||
|
||||
std::vector<CBlockIndex*> vSortedByHeight;
|
||||
vSortedByHeight.reserve(m_blockman.m_block_index.size());
|
||||
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
||||
vSortedByHeight.push_back(&block_index);
|
||||
}
|
||||
std::vector<CBlockIndex*> vSortedByHeight{m_blockman.GetAllBlockIndices()};
|
||||
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||
CBlockIndexHeightOnlyComparator());
|
||||
|
||||
|
|
Loading…
Reference in a new issue