mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
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 <seb.kung@gmail.com>
This commit is contained in:
@@ -292,7 +292,7 @@ public:
|
||||
std::string ToString() const;
|
||||
|
||||
//! Check whether this block index entry is valid up to the passed validity level.
|
||||
bool IsValid(enum BlockStatus nUpTo = BLOCK_VALID_TRANSACTIONS) const
|
||||
bool IsValid(enum BlockStatus nUpTo) const
|
||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
|
||||
@@ -30,7 +30,7 @@ FUZZ_TARGET(chain)
|
||||
(void)disk_block_index->GetMedianTimePast();
|
||||
(void)disk_block_index->GetUndoPos();
|
||||
(void)disk_block_index->HaveNumChainTxs();
|
||||
(void)disk_block_index->IsValid();
|
||||
(void)disk_block_index->IsValid(BLOCK_VALID_TRANSACTIONS);
|
||||
}
|
||||
|
||||
const CBlockHeader block_header = disk_block_index->GetBlockHeader();
|
||||
|
||||
@@ -3851,7 +3851,7 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
|
||||
// Remove the invalidity flag from this block and all its descendants and ancestors.
|
||||
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
||||
if (!block_index.IsValid() && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) {
|
||||
if ((block_index.nStatus & BLOCK_FAILED_MASK) && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) {
|
||||
block_index.nStatus &= ~BLOCK_FAILED_MASK;
|
||||
m_blockman.m_dirty_blockindex.insert(&block_index);
|
||||
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
|
||||
|
||||
Reference in New Issue
Block a user