mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-23 21:22:32 +02:00
Merge bitcoin/bitcoin#33154: test: use local CBlockIndex
in block read hash mismatch check
cb173b8e93
test: use local `CBlockIndex` in block read hash mismatch test to avoid data race (Lőrinc) Pull request description: Avoid mutating the shared active tip `CBlockIndex` in the `blockmanager_readblock_hash_mismatch` test. Instead, construct a local `CBlockIndex` with only the required fields set, ensuring the test remains self-contained and hopefully eliminating the data race reported in https://github.com/bitcoin/bitcoin/issues/33150. ACKs for top commit: stickies-v: ACKcb173b8e93
maflcko: lgtm ACKcb173b8e93
Tree-SHA512: 790528db0659f8cc5b87ed2b316bf274af68edc6158b0ce8821baccddf8d9bc4074afcb7260e3a61d5013d24ab51cc5c31e36693b8fb5ab913a44229fd6ad36b
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user