Skip to content

Commit bc797d2

Browse files
committed
Merge bitcoin/bitcoin#33154: test: use local CBlockIndex in block read hash mismatch check
cb173b8 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 bitcoin/bitcoin#33150. ACKs for top commit: stickies-v: ACK cb173b8 maflcko: lgtm ACK cb173b8 Tree-SHA512: 790528db0659f8cc5b87ed2b316bf274af68edc6158b0ce8821baccddf8d9bc4074afcb7260e3a61d5013d24ab51cc5c31e36693b8fb5ab913a44229fd6ad36b
2 parents d3c58a5 + cb173b8 commit bc797d2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/test/blockmanager_tests.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,18 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
139139

140140
BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup)
141141
{
142-
CBlockIndex* fake_index{WITH_LOCK(m_node.chainman->GetMutex(), return m_node.chainman->ActiveChain().Tip())};
143-
fake_index->phashBlock = &uint256::ONE; // invalid block hash
142+
CBlockIndex index;
143+
{
144+
LOCK(cs_main);
145+
const auto tip{m_node.chainman->ActiveTip()};
146+
index.nStatus = tip->nStatus;
147+
index.nDataPos = tip->nDataPos;
148+
index.phashBlock = &uint256::ONE; // mismatched block hash
149+
}
144150

145151
ASSERT_DEBUG_LOG("GetHash() doesn't match index");
146-
CBlock dummy;
147-
BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(dummy, *fake_index));
152+
CBlock block;
153+
BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(block, index));
148154
}
149155

150156
BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)

0 commit comments

Comments
 (0)