Skip to content

Commit 0c1c730

Browse files
committed
validation: remove BLOCK_FAILED_MASK
since it's the same as BLOCK_FAILED_VALID now
1 parent af54459 commit 0c1c730

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

src/chain.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ enum BlockStatus : uint32_t {
123123
BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO,
124124

125125
BLOCK_FAILED_VALID = 32, //!< stage after last reached validness failed
126-
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID,
127126

128127
BLOCK_OPT_WITNESS = 128, //!< block data in blk*.dat was received with a witness-enforcing client
129128

@@ -296,7 +295,7 @@ class CBlockIndex
296295
{
297296
AssertLockHeld(::cs_main);
298297
assert(!(nUpTo & ~BLOCK_VALID_MASK)); // Only validity flags allowed.
299-
if (nStatus & BLOCK_FAILED_MASK)
298+
if (nStatus & BLOCK_FAILED_VALID)
300299
return false;
301300
return ((nStatus & BLOCK_VALID_MASK) >= nUpTo);
302301
}
@@ -307,7 +306,7 @@ class CBlockIndex
307306
{
308307
AssertLockHeld(::cs_main);
309308
assert(!(nUpTo & ~BLOCK_VALID_MASK)); // Only validity flags allowed.
310-
if (nStatus & BLOCK_FAILED_MASK) return false;
309+
if (nStatus & BLOCK_FAILED_VALID) return false;
311310

312311
if ((nStatus & BLOCK_VALID_MASK) < nUpTo) {
313312
nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo;

src/node/blockstorage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
461461
pindex->m_chain_tx_count = pindex->nTx;
462462
}
463463
}
464-
if (!(pindex->nStatus & BLOCK_FAILED_MASK) && pindex->pprev && (pindex->pprev->nStatus & BLOCK_FAILED_MASK)) {
464+
if (!(pindex->nStatus & BLOCK_FAILED_VALID) && pindex->pprev && (pindex->pprev->nStatus & BLOCK_FAILED_VALID)) {
465465
pindex->nStatus |= BLOCK_FAILED_VALID;
466466
m_dirty_blockindex.insert(pindex);
467467
}

src/rpc/blockchain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ static RPCHelpMan getchaintips()
15351535
if (active_chain.Contains(block)) {
15361536
// This block is part of the currently active chain.
15371537
status = "active";
1538-
} else if (block->nStatus & BLOCK_FAILED_MASK) {
1538+
} else if (block->nStatus & BLOCK_FAILED_VALID) {
15391539
// This block or one of its ancestors is invalid.
15401540
status = "invalid";
15411541
} else if (!block->HaveNumChainTxs()) {

src/rpc/mining.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static RPCHelpMan getblocktemplate()
711711
if (pindex) {
712712
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
713713
return "duplicate";
714-
if (pindex->nStatus & BLOCK_FAILED_MASK)
714+
if (pindex->nStatus & BLOCK_FAILED_VALID)
715715
return "duplicate-invalid";
716716
return "duplicate-inconclusive";
717717
}

src/test/fuzz/chain.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ FUZZ_TARGET(chain)
5050
BlockStatus::BLOCK_HAVE_UNDO,
5151
BlockStatus::BLOCK_HAVE_MASK,
5252
BlockStatus::BLOCK_FAILED_VALID,
53-
BlockStatus::BLOCK_FAILED_MASK,
5453
BlockStatus::BLOCK_OPT_WITNESS,
5554
});
5655
if (block_status & ~BLOCK_VALID_MASK) {

src/validation.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@ CBlockIndex* Chainstate::FindMostWorkChain()
32953295
// which block files have been deleted. Remove those as candidates
32963296
// for the most work chain if we come across them; we can't switch
32973297
// to a chain unless we have all the non-active-chain parent blocks.
3298-
bool fFailedChain = pindexTest->nStatus & BLOCK_FAILED_MASK;
3298+
bool fFailedChain = pindexTest->nStatus & BLOCK_FAILED_VALID;
32993299
bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA);
33003300
if (fFailedChain || fMissingData) {
33013301
// Candidate chain is not usable (either invalid or missing data)
@@ -3816,7 +3816,7 @@ void Chainstate::SetBlockFailureFlags(CBlockIndex* invalid_block)
38163816
AssertLockHeld(cs_main);
38173817

38183818
for (auto& [_, block_index] : m_blockman.m_block_index) {
3819-
if (block_index.GetAncestor(invalid_block->nHeight) == invalid_block && !(block_index.nStatus & BLOCK_FAILED_MASK)) {
3819+
if (block_index.GetAncestor(invalid_block->nHeight) == invalid_block && !(block_index.nStatus & BLOCK_FAILED_VALID)) {
38203820
block_index.nStatus |= BLOCK_FAILED_VALID;
38213821
}
38223822
}
@@ -3830,7 +3830,7 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38303830
// Remove the invalidity flag from this block and all its descendants.
38313831
for (auto& [_, block_index] : m_blockman.m_block_index) {
38323832
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
3833-
block_index.nStatus &= ~BLOCK_FAILED_MASK;
3833+
block_index.nStatus &= ~BLOCK_FAILED_VALID;
38343834
m_blockman.m_dirty_blockindex.insert(&block_index);
38353835
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
38363836
setBlockIndexCandidates.insert(&block_index);
@@ -3845,8 +3845,8 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38453845

38463846
// Remove the invalidity flag from all ancestors too.
38473847
while (pindex != nullptr) {
3848-
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3849-
pindex->nStatus &= ~BLOCK_FAILED_MASK;
3848+
if (pindex->nStatus & BLOCK_FAILED_VALID) {
3849+
pindex->nStatus &= ~BLOCK_FAILED_VALID;
38503850
m_blockman.m_dirty_blockindex.insert(pindex);
38513851
m_chainman.m_failed_blocks.erase(pindex);
38523852
}
@@ -4324,7 +4324,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
43244324
CBlockIndex* pindex = &(miSelf->second);
43254325
if (ppindex)
43264326
*ppindex = pindex;
4327-
if (pindex->nStatus & BLOCK_FAILED_MASK) {
4327+
if (pindex->nStatus & BLOCK_FAILED_VALID) {
43284328
LogDebug(BCLog::VALIDATION, "%s: block %s is marked invalid\n", __func__, hash.ToString());
43294329
return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate-invalid");
43304330
}
@@ -4344,7 +4344,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
43444344
return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, "prev-blk-not-found");
43454345
}
43464346
pindexPrev = &((*mi).second);
4347-
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) {
4347+
if (pindexPrev->nStatus & BLOCK_FAILED_VALID) {
43484348
LogDebug(BCLog::VALIDATION, "header %s has prev block invalid: %s\n", hash.ToString(), block.hashPrevBlock.ToString());
43494349
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
43504350
}
@@ -5027,7 +5027,7 @@ bool ChainstateManager::LoadBlockIndex()
50275027
chainstate->TryAddBlockIndexCandidate(pindex);
50285028
}
50295029
}
5030-
if (pindex->nStatus & BLOCK_FAILED_MASK && (!m_best_invalid || pindex->nChainWork > m_best_invalid->nChainWork)) {
5030+
if (pindex->nStatus & BLOCK_FAILED_VALID && (!m_best_invalid || pindex->nChainWork > m_best_invalid->nChainWork)) {
50315031
m_best_invalid = pindex;
50325032
}
50335033
if (pindex->IsValid(BLOCK_VALID_TREE) && (m_best_header == nullptr || CBlockIndexWorkComparator()(m_best_header, pindex)))
@@ -5388,7 +5388,7 @@ void ChainstateManager::CheckBlockIndex()
53885388
if ((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_SCRIPTS) assert(pindexFirstNotScriptsValid == nullptr); // SCRIPTS valid implies all parents are SCRIPTS valid
53895389
if (pindexFirstInvalid == nullptr) {
53905390
// Checks for not-invalid blocks.
5391-
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
5391+
assert((pindex->nStatus & BLOCK_FAILED_VALID) == 0); // The failed mask cannot be set for blocks without invalid parents.
53925392
}
53935393
// Make sure m_chain_tx_count sum is correctly computed.
53945394
if (!pindex->pprev) {
@@ -5735,7 +5735,7 @@ util::Result<CBlockIndex*> ChainstateManager::ActivateSnapshot(
57355735
base_blockhash.ToString()))};
57365736
}
57375737

5738-
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
5738+
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_VALID;
57395739
if (start_block_invalid) {
57405740
return util::Error{Untranslated(strprintf("The base block header (%s) is part of an invalid chain", base_blockhash.ToString()))};
57415741
}
@@ -6448,7 +6448,7 @@ void ChainstateManager::RecalculateBestHeader()
64486448
AssertLockHeld(cs_main);
64496449
m_best_header = ActiveChain().Tip();
64506450
for (auto& entry : m_blockman.m_block_index) {
6451-
if (!(entry.second.nStatus & BLOCK_FAILED_MASK) && m_best_header->nChainWork < entry.second.nChainWork) {
6451+
if (!(entry.second.nStatus & BLOCK_FAILED_VALID) && m_best_header->nChainWork < entry.second.nChainWork) {
64526452
m_best_header = &entry.second;
64536453
}
64546454
}

0 commit comments

Comments
 (0)