test: use local CBlockIndex in block read hash mismatch test to avoid data race

Co-authored-by: stickies-v <stickies-v@protonmail.com>
This commit is contained in:
Lőrincandstickies-v committed 2025-08-12 11:34:58 -07:00
1 parent 2bb06bcaf2
commit cb173b8e93
1 file changed
+10 -4
+10 -4
View File
@@ -139,12 +139,18 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup)
{
CBlockIndex* fake_index{WITH_LOCK(m_node.chainman->GetMutex(), return m_node.chainman->ActiveChain().Tip())};
fake_index->phashBlock = &uint256::ONE; // invalid block hash
CBlockIndex index;
{
LOCK(cs_main);
const auto tip{m_node.chainman->ActiveTip()};
index.nStatus = tip->nStatus;
index.nDataPos = tip->nDataPos;
index.phashBlock = &uint256::ONE; // mismatched block hash
}
ASSERT_DEBUG_LOG("GetHash() doesn't match index");
CBlock dummy;
BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(dummy, *fake_index));
CBlock block;
BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(block, index));
}
BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)