mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
test: check BlockStatus when InvalidateBlock is used
when a block is invalidated using InvalidateBlock, check that: 1. it's status is BLOCK_FAILED_VALID 2. it's children's status is BLOCK_FAILED_CHILD and not BLOCK_FAILED_VALID 3. it's ancestors are valid
This commit is contained in:
parent
c99667583d
commit
9e29653b42
1 changed files with 32 additions and 0 deletions
|
@ -117,4 +117,36 @@ BOOST_AUTO_TEST_CASE(num_chain_tx_max)
|
||||||
BOOST_CHECK_EQUAL(block_index.m_chain_tx_count, std::numeric_limits<uint64_t>::max());
|
BOOST_CHECK_EQUAL(block_index.m_chain_tx_count, std::numeric_limits<uint64_t>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(invalidate_block, TestChain100Setup)
|
||||||
|
{
|
||||||
|
const CChain& active{*WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return &Assert(m_node.chainman)->ActiveChain())};
|
||||||
|
|
||||||
|
// Check BlockStatus when doing InvalidateBlock()
|
||||||
|
BlockValidationState state;
|
||||||
|
auto* orig_tip = active.Tip();
|
||||||
|
int height_to_invalidate = orig_tip->nHeight - 10;
|
||||||
|
auto* tip_to_invalidate = active[height_to_invalidate];
|
||||||
|
m_node.chainman->ActiveChainstate().InvalidateBlock(state, tip_to_invalidate);
|
||||||
|
|
||||||
|
// 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_CHILD) == 0));
|
||||||
|
|
||||||
|
// check all ancestors of the invalidated block are validated up to BLOCK_VALID_TRANSACTIONS and are not invalid
|
||||||
|
auto pindex = tip_to_invalidate->pprev;
|
||||||
|
while (pindex) {
|
||||||
|
WITH_LOCK(::cs_main, assert(pindex->IsValid(BLOCK_VALID_TRANSACTIONS)));
|
||||||
|
WITH_LOCK(::cs_main, assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0));
|
||||||
|
pindex = pindex->pprev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check all descendants of the invalidated block are BLOCK_FAILED_CHILD
|
||||||
|
pindex = orig_tip;
|
||||||
|
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_CHILD));
|
||||||
|
pindex = pindex->pprev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Add table
Reference in a new issue