blockstorage: Make m_block_index own CBlockIndex's

Instead of having CBlockIndex's live on the heap, which requires manual
memory management, have them be owned by m_block_index. This means that
they will live and die with BlockManager.

A change to BlockManager::LookupBlockIndex:
- Previously, it was a const member function returning a non-const CBlockIndex*
- Now, there's are const and non-const versions of
  BlockManager::LookupBlockIndex returning a CBlockIndex with the same
  const-ness as the member function:
    (e.g. const CBlockIndex* LookupBlockIndex(...) const)

See next commit for some weirdness that this eliminates.

The range based for-loops are modernize (using auto + destructuring) in
a future commit.
This commit is contained in:
Carl Dong
2021-01-08 18:56:48 -05:00
parent c44e734dca
commit bec86ae326
5 changed files with 58 additions and 47 deletions

View File

@@ -1753,10 +1753,10 @@ static RPCHelpMan getchaintips()
std::set<const CBlockIndex*> setOrphans;
std::set<const CBlockIndex*> setPrevs;
for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex()) {
if (!active_chain.Contains(item.second)) {
setOrphans.insert(item.second);
setPrevs.insert(item.second->pprev);
for (const std::pair<const uint256, CBlockIndex>& item : chainman.BlockIndex()) {
if (!active_chain.Contains(&item.second)) {
setOrphans.insert(&item.second);
setPrevs.insert(item.second.pprev);
}
}