mirror of https://github.com/bitcoin/bitcoin.git
validation: remove BLOCK_FAILED_CHILD
even though we have a distinction between BLOCK_FAILED_VALID and BLOCK_FAILED_CHILD in the codebase, we don't use it for anything. since there's no functional difference between them and it's unnecessary code complexity to categorise them correctly, just mark as BLOCK_FAILED_VALID instead.
This commit is contained in:
parent
f284834170
commit
350b2ad29c
|
@ -123,7 +123,7 @@ enum BlockStatus : uint32_t {
|
||||||
BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO,
|
BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO,
|
||||||
|
|
||||||
BLOCK_FAILED_VALID = 32, //!< stage after last reached validness failed
|
BLOCK_FAILED_VALID = 32, //!< stage after last reached validness failed
|
||||||
BLOCK_FAILED_CHILD = 64, //!< descends from failed block
|
BLOCK_FAILED_CHILD = 64, //!< Unused flag that was previously set when descending from failed block
|
||||||
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD,
|
BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD,
|
||||||
|
|
||||||
BLOCK_OPT_WITNESS = 128, //!< block data in blk*.dat was received with a witness-enforcing client
|
BLOCK_OPT_WITNESS = 128, //!< block data in blk*.dat was received with a witness-enforcing client
|
||||||
|
|
|
@ -464,7 +464,7 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(pindex->nStatus & BLOCK_FAILED_MASK) && pindex->pprev && (pindex->pprev->nStatus & BLOCK_FAILED_MASK)) {
|
if (!(pindex->nStatus & BLOCK_FAILED_MASK) && pindex->pprev && (pindex->pprev->nStatus & BLOCK_FAILED_MASK)) {
|
||||||
pindex->nStatus |= BLOCK_FAILED_CHILD;
|
pindex->nStatus |= BLOCK_FAILED_VALID;
|
||||||
m_dirty_blockindex.insert(pindex);
|
m_dirty_blockindex.insert(pindex);
|
||||||
}
|
}
|
||||||
if (pindex->pprev) {
|
if (pindex->pprev) {
|
||||||
|
|
|
@ -130,7 +130,6 @@ BOOST_FIXTURE_TEST_CASE(invalidate_block, TestChain100Setup)
|
||||||
|
|
||||||
// tip_to_invalidate just got invalidated, so it's BLOCK_FAILED_VALID
|
// tip_to_invalidate just got invalidated, so it's BLOCK_FAILED_VALID
|
||||||
WITH_LOCK(::cs_main, assert(tip_to_invalidate->nStatus & BLOCK_FAILED_VALID));
|
WITH_LOCK(::cs_main, assert(tip_to_invalidate->nStatus & BLOCK_FAILED_VALID));
|
||||||
WITH_LOCK(::cs_main, assert((tip_to_invalidate->nStatus & BLOCK_FAILED_CHILD) == 0));
|
|
||||||
|
|
||||||
// check all ancestors of the invalidated block are validated up to BLOCK_VALID_TRANSACTIONS and are not invalid
|
// check all ancestors of the invalidated block are validated up to BLOCK_VALID_TRANSACTIONS and are not invalid
|
||||||
auto pindex = tip_to_invalidate->pprev;
|
auto pindex = tip_to_invalidate->pprev;
|
||||||
|
@ -140,18 +139,12 @@ BOOST_FIXTURE_TEST_CASE(invalidate_block, TestChain100Setup)
|
||||||
pindex = pindex->pprev;
|
pindex = pindex->pprev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check all descendants of the invalidated block are BLOCK_FAILED_CHILD
|
// check all descendants of the invalidated block are BLOCK_FAILED_VALID
|
||||||
pindex = orig_tip;
|
pindex = orig_tip;
|
||||||
while (pindex && pindex != tip_to_invalidate) {
|
while (pindex && pindex != tip_to_invalidate) {
|
||||||
WITH_LOCK(::cs_main, assert((pindex->nStatus & BLOCK_FAILED_VALID) == 0));
|
WITH_LOCK(::cs_main, assert(pindex->nStatus & BLOCK_FAILED_VALID));
|
||||||
WITH_LOCK(::cs_main, assert(pindex->nStatus & BLOCK_FAILED_CHILD));
|
|
||||||
pindex = pindex->pprev;
|
pindex = pindex->pprev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't mark already invalidated block (orig_tip is BLOCK_FAILED_CHILD) with BLOCK_FAILED_VALID again
|
|
||||||
m_node.chainman->ActiveChainstate().InvalidateBlock(state, orig_tip);
|
|
||||||
WITH_LOCK(::cs_main, assert(orig_tip->nStatus & BLOCK_FAILED_CHILD));
|
|
||||||
WITH_LOCK(::cs_main, assert((orig_tip->nStatus & BLOCK_FAILED_VALID) == 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
@ -50,7 +50,6 @@ FUZZ_TARGET(chain)
|
||||||
BlockStatus::BLOCK_HAVE_UNDO,
|
BlockStatus::BLOCK_HAVE_UNDO,
|
||||||
BlockStatus::BLOCK_HAVE_MASK,
|
BlockStatus::BLOCK_HAVE_MASK,
|
||||||
BlockStatus::BLOCK_FAILED_VALID,
|
BlockStatus::BLOCK_FAILED_VALID,
|
||||||
BlockStatus::BLOCK_FAILED_CHILD,
|
|
||||||
BlockStatus::BLOCK_FAILED_MASK,
|
BlockStatus::BLOCK_FAILED_MASK,
|
||||||
BlockStatus::BLOCK_OPT_WITNESS,
|
BlockStatus::BLOCK_OPT_WITNESS,
|
||||||
});
|
});
|
||||||
|
|
|
@ -3285,7 +3285,7 @@ CBlockIndex* Chainstate::FindMostWorkChain()
|
||||||
// Remove the entire chain from the set.
|
// Remove the entire chain from the set.
|
||||||
while (pindexTest != pindexFailed) {
|
while (pindexTest != pindexFailed) {
|
||||||
if (fFailedChain) {
|
if (fFailedChain) {
|
||||||
pindexFailed->nStatus |= BLOCK_FAILED_CHILD;
|
pindexFailed->nStatus |= BLOCK_FAILED_VALID;
|
||||||
m_blockman.m_dirty_blockindex.insert(pindexFailed);
|
m_blockman.m_dirty_blockindex.insert(pindexFailed);
|
||||||
} else if (fMissingData) {
|
} else if (fMissingData) {
|
||||||
// If we're missing data, then add back to m_blocks_unlinked,
|
// If we're missing data, then add back to m_blocks_unlinked,
|
||||||
|
@ -3828,7 +3828,7 @@ void Chainstate::SetBlockFailureFlags(CBlockIndex* invalid_block)
|
||||||
|
|
||||||
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
||||||
if (invalid_block != &block_index && block_index.GetAncestor(invalid_block->nHeight) == invalid_block) {
|
if (invalid_block != &block_index && block_index.GetAncestor(invalid_block->nHeight) == invalid_block) {
|
||||||
block_index.nStatus = (block_index.nStatus & ~BLOCK_FAILED_VALID) | BLOCK_FAILED_CHILD;
|
block_index.nStatus |= BLOCK_FAILED_VALID;
|
||||||
m_blockman.m_dirty_blockindex.insert(&block_index);
|
m_blockman.m_dirty_blockindex.insert(&block_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue