Skip to content

Commit 8cc3ac6

Browse files
validation: Don't use IsValid() to filter for invalid blocks
IsValid() also returns false for blocks that have not been validated yet up to the default validity level of BLOCK_VALID_TRANSACTIONS but are not marked as invalid - e.g. if we only know the header. Here, we specifically want to filter for invalid blocks. Also removes the default arg from IsValid() which is now unused outside of tests, to prevent this kind of misuse for the future. Co-authored-by: TheCharlatan <[email protected]>
1 parent 86d98b9 commit 8cc3ac6

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class CBlockIndex
292292
std::string ToString() const;
293293

294294
//! Check whether this block index entry is valid up to the passed validity level.
295-
bool IsValid(enum BlockStatus nUpTo = BLOCK_VALID_TRANSACTIONS) const
295+
bool IsValid(enum BlockStatus nUpTo) const
296296
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
297297
{
298298
AssertLockHeld(::cs_main);

src/test/fuzz/chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ FUZZ_TARGET(chain)
3030
(void)disk_block_index->GetMedianTimePast();
3131
(void)disk_block_index->GetUndoPos();
3232
(void)disk_block_index->HaveNumChainTxs();
33-
(void)disk_block_index->IsValid();
33+
(void)disk_block_index->IsValid(BLOCK_VALID_TRANSACTIONS);
3434
}
3535

3636
const CBlockHeader block_header = disk_block_index->GetBlockHeader();

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3851,7 +3851,7 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38513851

38523852
// Remove the invalidity flag from this block and all its descendants and ancestors.
38533853
for (auto& [_, block_index] : m_blockman.m_block_index) {
3854-
if (!block_index.IsValid() && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) {
3854+
if ((block_index.nStatus & BLOCK_FAILED_MASK) && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) {
38553855
block_index.nStatus &= ~BLOCK_FAILED_MASK;
38563856
m_blockman.m_dirty_blockindex.insert(&block_index);
38573857
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {

0 commit comments

Comments
 (0)