mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 10:42:13 +02:00
test: check LoadBlockIndex correctly recomputes invalidity flags
Add a test for block index transitioning from legacy BLOCK_FAILED_CHILD to BLOCK_FAILED_VALID behavior. In the scenario where a valid block has a BLOCK_FAILED_CHILD parent and a BLOCK_FAILED_VALID grandparent, ensure that all three blocks are correctly marked as BLOCK_FAILED_VALID after reloading the block index.
This commit is contained in:
@@ -591,6 +591,31 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
|
|||||||
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.size(), num_indexes - last_assumed_valid_idx + 1);
|
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.size(), num_indexes - last_assumed_valid_idx + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(loadblockindex_invalid_descendants, TestChain100Setup)
|
||||||
|
{
|
||||||
|
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||||
|
// consider the chain of blocks grand_parent <- parent <- child
|
||||||
|
// intentionally mark:
|
||||||
|
// - grand_parent: BLOCK_FAILED_VALID
|
||||||
|
// - parent: BLOCK_FAILED_CHILD
|
||||||
|
// - child: not invalid
|
||||||
|
// Test that when the block index is loaded, all blocks are marked as BLOCK_FAILED_VALID
|
||||||
|
auto* child{m_node.chainman->ActiveChain().Tip()};
|
||||||
|
auto* parent{child->pprev};
|
||||||
|
auto* grand_parent{parent->pprev};
|
||||||
|
grand_parent->nStatus = (grand_parent->nStatus | BLOCK_FAILED_VALID);
|
||||||
|
parent->nStatus = (parent->nStatus & ~BLOCK_FAILED_VALID) | BLOCK_FAILED_CHILD;
|
||||||
|
child->nStatus = (child->nStatus & ~BLOCK_FAILED_VALID);
|
||||||
|
|
||||||
|
// Reload block index to recompute block status validity flags.
|
||||||
|
m_node.chainman->LoadBlockIndex();
|
||||||
|
|
||||||
|
// check grand_parent, parent, child is marked as BLOCK_FAILED_VALID after reloading the block index
|
||||||
|
BOOST_CHECK(grand_parent->nStatus & BLOCK_FAILED_VALID);
|
||||||
|
BOOST_CHECK(parent->nStatus & BLOCK_FAILED_VALID);
|
||||||
|
BOOST_CHECK(child->nStatus & BLOCK_FAILED_VALID);
|
||||||
|
}
|
||||||
|
|
||||||
//! Ensure that snapshot chainstate can be loaded when found on disk after a
|
//! Ensure that snapshot chainstate can be loaded when found on disk after a
|
||||||
//! restart, and that new blocks can be connected to both chainstates.
|
//! restart, and that new blocks can be connected to both chainstates.
|
||||||
BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_init, SnapshotTestSetup)
|
BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_init, SnapshotTestSetup)
|
||||||
|
|||||||
Reference in New Issue
Block a user