aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@gmail.com>2019-06-24 15:22:33 -0400
committerJames O'Beirne <james.obeirne@gmail.com>2019-07-08 11:33:12 -0400
commit4ed55dfcd7894fd5ba6395f244a17ab1f8e786d4 (patch)
tree08cf711fb536abef170886660f3d5fa6ffd0592d /src/validation.cpp
parent613c46fe9e39f55b0f0daa18fee20b4120db2539 (diff)
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.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 75d5bb9fe6..3e71928d17 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3705,7 +3705,10 @@ CBlockIndex * BlockManager::InsertBlockIndex(const uint256& hash)
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); }))
return false;
@@ -3743,8 +3746,9 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params, CBl
pindex->nStatus |= BLOCK_FAILED_CHILD;
setDirtyBlockIndex.insert(pindex);
}
- if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->HaveTxsDownloaded() || pindex->pprev == nullptr))
- ::ChainstateActive().setBlockIndexCandidates.insert(pindex);
+ if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && (pindex->HaveTxsDownloaded() || pindex->pprev == nullptr)) {
+ block_index_candidates.insert(pindex);
+ }
if (pindex->nStatus & BLOCK_FAILED_MASK && (!pindexBestInvalid || pindex->nChainWork > pindexBestInvalid->nChainWork))
pindexBestInvalid = pindex;
if (pindex->pprev)
@@ -3769,7 +3773,8 @@ void BlockManager::Unload() {
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;
// Load block file info