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:
@@ -17,6 +17,7 @@ BOOST_FIXTURE_TEST_SUITE(interfaces_tests, TestChain100Setup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(findBlock)
|
||||
{
|
||||
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||
auto& chain = m_node.chain;
|
||||
const CChain& active = Assert(m_node.chainman)->ActiveChain();
|
||||
|
||||
@@ -61,6 +62,7 @@ BOOST_AUTO_TEST_CASE(findBlock)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(findFirstBlockWithTimeAndHeight)
|
||||
{
|
||||
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||
auto& chain = m_node.chain;
|
||||
const CChain& active = Assert(m_node.chainman)->ActiveChain();
|
||||
uint256 hash;
|
||||
@@ -73,6 +75,7 @@ BOOST_AUTO_TEST_CASE(findFirstBlockWithTimeAndHeight)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(findAncestorByHeight)
|
||||
{
|
||||
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||
auto& chain = m_node.chain;
|
||||
const CChain& active = Assert(m_node.chainman)->ActiveChain();
|
||||
uint256 hash;
|
||||
@@ -83,6 +86,7 @@ BOOST_AUTO_TEST_CASE(findAncestorByHeight)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(findAncestorByHash)
|
||||
{
|
||||
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||
auto& chain = m_node.chain;
|
||||
const CChain& active = Assert(m_node.chainman)->ActiveChain();
|
||||
int height = -1;
|
||||
@@ -94,7 +98,7 @@ BOOST_AUTO_TEST_CASE(findAncestorByHash)
|
||||
BOOST_AUTO_TEST_CASE(findCommonAncestor)
|
||||
{
|
||||
auto& chain = m_node.chain;
|
||||
const CChain& active = Assert(m_node.chainman)->ActiveChain();
|
||||
const CChain& active = WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return Assert(m_node.chainman)->ActiveChain());
|
||||
auto* orig_tip = active.Tip();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
BlockValidationState state;
|
||||
|
||||
Reference in New Issue
Block a user