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 #33150.
CBlockIndex
in block read hash mismatch check
#33154
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 #33150.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33154.
See the guideline for information on the review process. A summary of reviews will appear here.
143- fake_index->phashBlock = &uint256::ONE; // invalid block hash
144+ CBlockIndex index;
145+ {
146+ LOCK(cs_main);
147+ index.nStatus = BLOCK_HAVE_DATA;
148+ index.nDataPos = STORAGE_HEADER_BYTES;
0 index.nDataPos = m_node.chainman->ActiveTip()->nDataPos;
nit: Would be nice to document explicitly what block this reads (and drop the hardcoded implementation detail) and also use the m_node.chainman->GetMutex()
for new code.
to document explicitly what block this reads
Used the tip
for the rest of the values.
use the m_node.chainman->GetMutex() for new code
It seems to me that nStatus
and nDataPos
need an explicit cs_main
lock - can you point to a similar code which does it the way you think should be done here as well?
138@@ -139,12 +139,17 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
139
140 BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup)
141 {
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
144+ CBlockIndex index;
145+ {
146+ LOCK(cs_main);
147+ index.nStatus = BLOCK_HAVE_DATA;
nit: Can be removed?
Is the test passing for you that way? I’m getting:
unknown location:0: fatal error: in “blockmanager_tests/blockmanager_readblock_hash_mismatch”: std::runtime_error: ‘GetHash() doesn’t match index’ not found in debug log