mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
refactor: Add lock annotations to Active* methods
This is a refactor, putting the burden to think about thread safety to the caller. Otherwise, there is a risk that the caller will assume thread safety where none exists, as is evident in the previous two commits.
This commit is contained in:
@@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
|
||||
|
||||
// Run the test multiple times
|
||||
for (int test_runs = 3; test_runs > 0; --test_runs) {
|
||||
BOOST_CHECK_EQUAL(last_mined->GetHash(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||
BOOST_CHECK_EQUAL(last_mined->GetHash(), WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain().Tip()->GetBlockHash()));
|
||||
|
||||
// Later on split from here
|
||||
const uint256 split_hash{last_mined->hashPrevBlock};
|
||||
@@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
|
||||
ProcessBlock(b);
|
||||
}
|
||||
// Check that the reorg was eventually successful
|
||||
BOOST_CHECK_EQUAL(last_mined->GetHash(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||
BOOST_CHECK_EQUAL(last_mined->GetHash(), WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain().Tip()->GetBlockHash()));
|
||||
|
||||
// We can join the other thread, which returns when the reorg was successful
|
||||
rpc_thread.join();
|
||||
@@ -325,6 +325,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(witness_commitment_index)
|
||||
{
|
||||
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||
CScript pubKey;
|
||||
pubKey << 1 << OP_TRUE;
|
||||
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(pubKey);
|
||||
|
||||
Reference in New Issue
Block a user