Skip to content

Commit c03ff89

Browse files
committed
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
1 parent 27b5abf commit c03ff89

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test/interfaces_tests.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,32 @@ BOOST_AUTO_TEST_CASE(findCommonAncestor)
123123
BOOST_CHECK(!chain->findCommonAncestor({}, orig_tip->GetBlockHash(), {}, {}, FoundBlock().hash(orig_hash)));
124124
BOOST_CHECK_EQUAL(active_hash, active.Tip()->GetBlockHash());
125125
BOOST_CHECK_EQUAL(orig_hash, orig_tip->GetBlockHash());
126+
127+
// Check BlockStatus when doing InvalidateBlock()
128+
BlockValidationState state;
129+
orig_tip = active.Tip();
130+
int height_to_invalidate = orig_tip->nHeight - 10;
131+
auto* tip_to_invalidate = active[height_to_invalidate];
132+
m_node.chainman->ActiveChainstate().InvalidateBlock(state, tip_to_invalidate);
133+
134+
// tip_to_invalidate just got invalidated, so it's BLOCK_FAILED_VALID
135+
WITH_LOCK(::cs_main, assert(tip_to_invalidate->nStatus & BLOCK_FAILED_VALID));
136+
WITH_LOCK(::cs_main, assert((tip_to_invalidate->nStatus & BLOCK_FAILED_CHILD) == 0));
137+
138+
// check all ancestors of block are BLOCK_VALID_TREE
139+
auto pindex = tip_to_invalidate->pprev;
140+
while (pindex) {
141+
WITH_LOCK(::cs_main, assert(pindex->nStatus & BLOCK_HAVE_DATA));
142+
pindex = pindex->pprev;
143+
}
144+
145+
// check all descendants of block are BLOCK_FAILED_CHILD
146+
pindex = orig_tip;
147+
while (pindex && pindex != tip_to_invalidate) {
148+
WITH_LOCK(::cs_main, assert((pindex->nStatus & BLOCK_FAILED_VALID) == 0));
149+
WITH_LOCK(::cs_main, assert(pindex->nStatus & BLOCK_FAILED_CHILD));
150+
pindex = pindex->pprev;
151+
}
126152
}
127153

128154
BOOST_AUTO_TEST_CASE(hasBlocks)

0 commit comments

Comments
 (0)