mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +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:
@@ -49,12 +49,12 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
auto all = manager.GetAll();
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(all.begin(), all.end(), chainstates.begin(), chainstates.end());
|
||||
|
||||
auto& active_chain = manager.ActiveChain();
|
||||
auto& active_chain = WITH_LOCK(manager.GetMutex(), return manager.ActiveChain());
|
||||
BOOST_CHECK_EQUAL(&active_chain, &c1.m_chain);
|
||||
|
||||
BOOST_CHECK_EQUAL(manager.ActiveHeight(), -1);
|
||||
BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), -1);
|
||||
|
||||
auto active_tip = manager.ActiveTip();
|
||||
auto active_tip = WITH_LOCK(manager.GetMutex(), return manager.ActiveTip());
|
||||
auto exp_tip = c1.m_chain.Tip();
|
||||
BOOST_CHECK_EQUAL(active_tip, exp_tip);
|
||||
|
||||
@@ -84,12 +84,12 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
auto all2 = manager.GetAll();
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(all2.begin(), all2.end(), chainstates.begin(), chainstates.end());
|
||||
|
||||
auto& active_chain2 = manager.ActiveChain();
|
||||
auto& active_chain2 = WITH_LOCK(manager.GetMutex(), return manager.ActiveChain());
|
||||
BOOST_CHECK_EQUAL(&active_chain2, &c2.m_chain);
|
||||
|
||||
BOOST_CHECK_EQUAL(manager.ActiveHeight(), 0);
|
||||
BOOST_CHECK_EQUAL(WITH_LOCK(manager.GetMutex(), return manager.ActiveHeight()), 0);
|
||||
|
||||
auto active_tip2 = manager.ActiveTip();
|
||||
auto active_tip2 = WITH_LOCK(manager.GetMutex(), return manager.ActiveTip());
|
||||
auto exp_tip2 = c2.m_chain.Tip();
|
||||
BOOST_CHECK_EQUAL(active_tip2, exp_tip2);
|
||||
|
||||
@@ -236,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
|
||||
BOOST_CHECK(WITH_LOCK(::cs_main, return !chainman.ActiveChain().Genesis()->IsAssumedValid()));
|
||||
|
||||
const AssumeutxoData& au_data = *ExpectedAssumeutxo(snapshot_height, ::Params());
|
||||
const CBlockIndex* tip = chainman.ActiveTip();
|
||||
const CBlockIndex* tip = WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip());
|
||||
|
||||
BOOST_CHECK_EQUAL(tip->nChainTx, au_data.nChainTx);
|
||||
|
||||
@@ -335,7 +335,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
|
||||
const int assumed_valid_start_idx = last_assumed_valid_idx - expected_assumed_valid;
|
||||
|
||||
CBlockIndex* validated_tip{nullptr};
|
||||
CBlockIndex* assumed_tip{chainman.ActiveChain().Tip()};
|
||||
CBlockIndex* assumed_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())};
|
||||
|
||||
auto reload_all_block_indexes = [&]() {
|
||||
for (CChainState* cs : chainman.GetAll()) {
|
||||
|
||||
Reference in New Issue
Block a user