refactoring: add block_index_candidates arg to LoadBlockIndex
Prevents BlockManager from having to reference ChainstateActive() within one of its methods which improves encapsulation and makes testing easier.
This commit is contained in:
parent
613c46fe9e
commit
4ed55dfcd7
2 changed files with 20 additions and 5 deletions
|
@ -3705,7 +3705,10 @@ CBlockIndex * BlockManager::InsertBlockIndex(const uint256& hash)
|
||||||
return pindexNew;
|
return pindexNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree)
|
bool BlockManager::LoadBlockIndex(
|
||||||
|
const Consensus::Params& consensus_params,
|
||||||
|
CBlockTreeDB& blocktree,
|
||||||
|
std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
|
||||||
{
|
{
|
||||||
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); }))
|
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); }))
|
||||||
return false;
|
return false;
|
||||||
|
@ -3743,8 +3746,9 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params, CBl
|
||||||
pindex->nStatus |= BLOCK_FAILED_CHILD;
|
pindex->nStatus |= BLOCK_FAILED_CHILD;
|
||||||
setDirtyBlockIndex.insert(pindex);
|
setDirtyBlockIndex.insert(pindex);
|
||||||
}
|
}
|
||||||
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->HaveTxsDownloaded() || pindex->pprev == nullptr))
|
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->HaveTxsDownloaded() || pindex->pprev == nullptr)) {
|
||||||
::ChainstateActive().setBlockIndexCandidates.insert(pindex);
|
block_index_candidates.insert(pindex);
|
||||||
|
}
|
||||||
if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork))
|
if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork))
|
||||||
pindexBestInvalid = pindex;
|
pindexBestInvalid = pindex;
|
||||||
if (pindex->pprev)
|
if (pindex->pprev)
|
||||||
|
@ -3769,7 +3773,8 @@ void BlockManager::Unload() {
|
||||||
|
|
||||||
bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||||
{
|
{
|
||||||
if (!g_blockman.LoadBlockIndex(chainparams.GetConsensus(), *pblocktree))
|
if (!g_blockman.LoadBlockIndex(
|
||||||
|
chainparams.GetConsensus(), *pblocktree, ::ChainstateActive().setBlockIndexCandidates))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Load block file info
|
// Load block file info
|
||||||
|
|
|
@ -475,9 +475,19 @@ public:
|
||||||
*/
|
*/
|
||||||
std::multimap<CBlockIndex*, CBlockIndex*> m_blocks_unlinked;
|
std::multimap<CBlockIndex*, CBlockIndex*> m_blocks_unlinked;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the blocktree off disk and into memory. Populate certain metadata
|
||||||
|
* per index entry (nStatus, nChainWork, nTimeMax, etc.) as well as peripheral
|
||||||
|
* collections like setDirtyBlockIndex.
|
||||||
|
*
|
||||||
|
* @param[out] block_index_candidates Fill this set with any valid blocks for
|
||||||
|
* which we've downloaded all transactions.
|
||||||
|
*/
|
||||||
bool LoadBlockIndex(
|
bool LoadBlockIndex(
|
||||||
const Consensus::Params& consensus_params,
|
const Consensus::Params& consensus_params,
|
||||||
CBlockTreeDB& blocktree) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
CBlockTreeDB& blocktree,
|
||||||
|
std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
|
||||||
|
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/** Clear all data members. */
|
/** Clear all data members. */
|
||||||
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
Loading…
Add table
Reference in a new issue