Add and use BlockManager::GetAllBlockIndices
This commit is contained in:
1 parent
28ba0313ea
commit
f865cf8ded
3 files changed
+15
-10
No files matched your search
@@ -56,6 +56,17 @@ static FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false);
|
|||||||
static FlatFileSeq BlockFileSeq();
|
static FlatFileSeq BlockFileSeq();
|
||||||
static FlatFileSeq UndoFileSeq();
|
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)
|
CBlockIndex* BlockManager::LookupBlockIndex(const uint256& hash)
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
@@ -242,11 +253,7 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate nChainWork
|
// Calculate nChainWork
|
||||||
std::vector<CBlockIndex*> vSortedByHeight;
|
std::vector<CBlockIndex*> vSortedByHeight{GetAllBlockIndices()};
|
||||||
vSortedByHeight.reserve(m_block_index.size());
|
|
||||||
for (auto& [_, block_index] : m_block_index) {
|
|
||||||
vSortedByHeight.push_back(&block_index);
|
|
||||||
}
|
|
||||||
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||||
CBlockIndexHeightOnlyComparator());
|
CBlockIndexHeightOnlyComparator());
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
BlockMap m_block_index GUARDED_BY(cs_main);
|
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.
|
* 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.
|
* Pruned nodes may have entries where B is missing data.
|
||||||
|
|||||||
+1
-5
@@ -4069,11 +4069,7 @@ bool ChainstateManager::LoadBlockIndex()
|
|||||||
bool ret = m_blockman.LoadBlockIndexDB();
|
bool ret = m_blockman.LoadBlockIndexDB();
|
||||||
if (!ret) return false;
|
if (!ret) return false;
|
||||||
|
|
||||||
std::vector<CBlockIndex*> vSortedByHeight;
|
std::vector<CBlockIndex*> vSortedByHeight{m_blockman.GetAllBlockIndices()};
|
||||||
vSortedByHeight.reserve(m_blockman.m_block_index.size());
|
|
||||||
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
|
||||||
vSortedByHeight.push_back(&block_index);
|
|
||||||
}
|
|
||||||
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||||
CBlockIndexHeightOnlyComparator());
|
CBlockIndexHeightOnlyComparator());
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user