Skip to content

Commit facd213

Browse files
author
MarcoFalke
committed
Move m_failed_blocks to ChainstateManager
The member is unrelated to block storage (BlockManager). It is related to validation. Fix the confusion by moving it. Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
1 parent fa47b5c commit facd213

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

src/validation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ void CChainState::InvalidBlockFound(CBlockIndex* pindex, const BlockValidationSt
12911291
{
12921292
if (state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
12931293
pindex->nStatus |= BLOCK_FAILED_VALID;
1294-
m_blockman.m_failed_blocks.insert(pindex);
1294+
m_chainman.m_failed_blocks.insert(pindex);
12951295
setDirtyBlockIndex.insert(pindex);
12961296
setBlockIndexCandidates.erase(pindex);
12971297
InvalidChainFound(pindex);
@@ -2844,7 +2844,7 @@ bool CChainState::InvalidateBlock(BlockValidationState& state, CBlockIndex* pind
28442844
to_mark_failed->nStatus |= BLOCK_FAILED_VALID;
28452845
setDirtyBlockIndex.insert(to_mark_failed);
28462846
setBlockIndexCandidates.erase(to_mark_failed);
2847-
m_blockman.m_failed_blocks.insert(to_mark_failed);
2847+
m_chainman.m_failed_blocks.insert(to_mark_failed);
28482848

28492849
// If any new blocks somehow arrived while we were disconnecting
28502850
// (above), then the pre-calculation of what should go into
@@ -2889,7 +2889,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
28892889
// Reset invalid block marker if it was pointing to one of those.
28902890
pindexBestInvalid = nullptr;
28912891
}
2892-
m_blockman.m_failed_blocks.erase(it->second);
2892+
m_chainman.m_failed_blocks.erase(it->second);
28932893
}
28942894
it++;
28952895
}
@@ -2899,7 +2899,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
28992899
if (pindex->nStatus & BLOCK_FAILED_MASK) {
29002900
pindex->nStatus &= ~BLOCK_FAILED_MASK;
29012901
setDirtyBlockIndex.insert(pindex);
2902-
m_blockman.m_failed_blocks.erase(pindex);
2902+
m_chainman.m_failed_blocks.erase(pindex);
29032903
}
29042904
pindex = pindex->pprev;
29052905
}
@@ -3325,7 +3325,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
33253325
// hasn't been validated up to BLOCK_VALID_SCRIPTS. This is a performance
33263326
// optimization, in the common case of adding a new block to the tip,
33273327
// we don't need to iterate over the failed blocks list.
3328-
for (const CBlockIndex* failedit : m_blockman.m_failed_blocks) {
3328+
for (const CBlockIndex* failedit : m_failed_blocks) {
33293329
if (pindexPrev->GetAncestor(failedit->nHeight) == failedit) {
33303330
assert(failedit->nStatus & BLOCK_FAILED_VALID);
33313331
CBlockIndex* invalid_walk = pindexPrev;
@@ -3804,7 +3804,6 @@ bool BlockManager::LoadBlockIndex(
38043804
}
38053805

38063806
void BlockManager::Unload() {
3807-
m_failed_blocks.clear();
38083807
m_blocks_unlinked.clear();
38093808

38103809
for (const BlockMap::value_type& entry : m_block_index) {
@@ -5119,6 +5118,7 @@ void ChainstateManager::Unload()
51195118
chainstate->UnloadBlockIndex();
51205119
}
51215120

5121+
m_failed_blocks.clear();
51225122
m_blockman.Unload();
51235123
}
51245124

src/validation.h

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -405,26 +405,6 @@ class BlockManager
405405
public:
406406
BlockMap m_block_index GUARDED_BY(cs_main);
407407

408-
/** In order to efficiently track invalidity of headers, we keep the set of
409-
* blocks which we tried to connect and found to be invalid here (ie which
410-
* were set to BLOCK_FAILED_VALID since the last restart). We can then
411-
* walk this set and check if a new header is a descendant of something in
412-
* this set, preventing us from having to walk m_block_index when we try
413-
* to connect a bad block and fail.
414-
*
415-
* While this is more complicated than marking everything which descends
416-
* from an invalid block as invalid at the time we discover it to be
417-
* invalid, doing so would require walking all of m_block_index to find all
418-
* descendants. Since this case should be very rare, keeping track of all
419-
* BLOCK_FAILED_VALID blocks in a set should be just fine and work just as
420-
* well.
421-
*
422-
* Because we already walk m_block_index in height-order at startup, we go
423-
* ahead and mark descendants of invalid blocks as FAILED_CHILD at that time,
424-
* instead of putting things in this set.
425-
*/
426-
std::set<CBlockIndex*> m_failed_blocks;
427-
428408
/**
429409
* All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
430410
* Pruned nodes may have entries where B is missing data.
@@ -909,6 +889,27 @@ class ChainstateManager
909889
//! chainstate to avoid duplicating block metadata.
910890
BlockManager m_blockman GUARDED_BY(::cs_main);
911891

892+
/**
893+
* In order to efficiently track invalidity of headers, we keep the set of
894+
* blocks which we tried to connect and found to be invalid here (ie which
895+
* were set to BLOCK_FAILED_VALID since the last restart). We can then
896+
* walk this set and check if a new header is a descendant of something in
897+
* this set, preventing us from having to walk m_block_index when we try
898+
* to connect a bad block and fail.
899+
*
900+
* While this is more complicated than marking everything which descends
901+
* from an invalid block as invalid at the time we discover it to be
902+
* invalid, doing so would require walking all of m_block_index to find all
903+
* descendants. Since this case should be very rare, keeping track of all
904+
* BLOCK_FAILED_VALID blocks in a set should be just fine and work just as
905+
* well.
906+
*
907+
* Because we already walk m_block_index in height-order at startup, we go
908+
* ahead and mark descendants of invalid blocks as FAILED_CHILD at that time,
909+
* instead of putting things in this set.
910+
*/
911+
std::set<CBlockIndex*> m_failed_blocks;
912+
912913
//! The total number of bytes available for us to use across all in-memory
913914
//! coins caches. This will be split somehow across chainstates.
914915
int64_t m_total_coinstip_cache{0};

0 commit comments

Comments
 (0)