Skip to content

Commit ed56dbd

Browse files
committed
refactor: don't use globals to access members we can directly access
FlushStateToDisk and {Enforce, Invalidate, MarkConflicting}Block are all CChainState functions, no need to access our own members through chainstate globals when we can access them directly.
1 parent c48c0e7 commit ed56dbd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/validation.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -2573,8 +2573,8 @@ bool CChainState::FlushStateToDisk(
25732573
std::set<int> setFilesToPrune;
25742574
bool full_flush_completed = false;
25752575

2576-
const size_t coins_count = ::ChainstateActive().CoinsTip().GetCacheSize();
2577-
const size_t coins_mem_usage = ::ChainstateActive().CoinsTip().DynamicMemoryUsage();
2576+
const size_t coins_count = CoinsTip().GetCacheSize();
2577+
const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage();
25782578

25792579
try {
25802580
{
@@ -3448,8 +3448,8 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
34483448
// it up here, this should be an essentially unobservable error.
34493449
// Loop back over all block index entries and add any missing entries
34503450
// to setBlockIndexCandidates.
3451-
BlockMap::iterator it = g_chainman.BlockIndex().begin();
3452-
while (it != g_chainman.BlockIndex().end()) {
3451+
BlockMap::iterator it = m_blockman.m_block_index.begin();
3452+
while (it != m_blockman.m_block_index.end()) {
34533453
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && !(it->second->nStatus & BLOCK_CONFLICT_CHAINLOCK) && it->second->HaveTxsDownloaded() && !setBlockIndexCandidates.value_comp()(it->second, m_chain.Tip())) {
34543454
setBlockIndexCandidates.insert(it->second);
34553455
}
@@ -3479,7 +3479,7 @@ void CChainState::EnforceBlock(BlockValidationState& state, const CBlockIndex *p
34793479

34803480
while (pindex_walk && !m_chain.Contains(pindex_walk)) {
34813481
// Mark all blocks that have the same prevBlockHash but are not equal to blockHash as conflicting
3482-
auto itp = g_chainman.PrevBlockIndex().equal_range(pindex_walk->pprev->GetBlockHash());
3482+
auto itp = m_blockman.m_prev_block_index.equal_range(pindex_walk->pprev->GetBlockHash());
34833483
for (auto jt = itp.first; jt != itp.second; ++jt) {
34843484
if (jt->second == pindex_walk) {
34853485
continue;
@@ -3552,8 +3552,8 @@ bool CChainState::MarkConflictingBlock(BlockValidationState& state, CBlockIndex
35523552

35533553
// The resulting new best tip may not be in setBlockIndexCandidates anymore, so
35543554
// add it again.
3555-
BlockMap::iterator it = g_chainman.BlockIndex().begin();
3556-
while (it != g_chainman.BlockIndex().end()) {
3555+
BlockMap::iterator it = m_blockman.m_block_index.begin();
3556+
while (it != m_blockman.m_block_index.end()) {
35573557
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && !(it->second->nStatus & BLOCK_CONFLICT_CHAINLOCK) && it->second->HaveTxsDownloaded() && !setBlockIndexCandidates.value_comp()(it->second, m_chain.Tip())) {
35583558
setBlockIndexCandidates.insert(it->second);
35593559
}
@@ -4265,8 +4265,8 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
42654265
return AbortNode(state, std::string("System error: ") + e.what());
42664266
}
42674267

4268-
if (::ChainstateActive().CanFlushToDisk()) {
4269-
::ChainstateActive().FlushStateToDisk(state, FlushStateMode::NONE);
4268+
if (CanFlushToDisk()) {
4269+
FlushStateToDisk(state, FlushStateMode::NONE);
42704270
}
42714271

42724272
CheckBlockIndex();

0 commit comments

Comments
 (0)