Skip to content

Commit fa18586

Browse files
author
MarcoFalke
committed
refactor: Add missing GUARDED_BY(m_tip_block_mutex)
Found by Cory Fields in bitcoin/bitcoin#30409 (comment)
1 parent fa4c075 commit fa18586

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/node/kernel_notifications.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class KernelNotifications : public kernel::Notifications
6060
Mutex m_tip_block_mutex;
6161
std::condition_variable m_tip_block_cv;
6262
//! The block for which the last blockTip notification was received for.
63-
uint256 m_tip_block;
63+
uint256 m_tip_block GUARDED_BY(m_tip_block_mutex);
6464

6565
private:
6666
util::SignalInterrupt& m_shutdown;

src/test/validation_chainstate_tests.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
7070
BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
7171
{
7272
ChainstateManager& chainman = *Assert(m_node.chainman);
73-
uint256 curr_tip = m_node.notifications->m_tip_block;
73+
const auto get_notify_tip{[&]() {
74+
LOCK(m_node.notifications->m_tip_block_mutex);
75+
return m_node.notifications->m_tip_block;
76+
}};
77+
uint256 curr_tip = get_notify_tip();
7478

7579
// Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can
7680
// be found.
7781
mineBlocks(10);
7882

7983
// After adding some blocks to the tip, best block should have changed.
80-
BOOST_CHECK(m_node.notifications->m_tip_block != curr_tip);
84+
BOOST_CHECK(get_notify_tip() != curr_tip);
8185

8286
// Grab block 1 from disk; we'll add it to the background chain later.
8387
std::shared_ptr<CBlock> pblockone = std::make_shared<CBlock>();
@@ -92,15 +96,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
9296
// Ensure our active chain is the snapshot chainstate.
9397
BOOST_CHECK(WITH_LOCK(::cs_main, return chainman.IsSnapshotActive()));
9498

95-
curr_tip = m_node.notifications->m_tip_block;
99+
curr_tip = get_notify_tip();
96100

97101
// Mine a new block on top of the activated snapshot chainstate.
98102
mineBlocks(1); // Defined in TestChain100Setup.
99103

100104
// After adding some blocks to the snapshot tip, best block should have changed.
101-
BOOST_CHECK(m_node.notifications->m_tip_block != curr_tip);
105+
BOOST_CHECK(get_notify_tip() != curr_tip);
102106

103-
curr_tip = m_node.notifications->m_tip_block;
107+
curr_tip = get_notify_tip();
104108

105109
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 2);
106110

@@ -136,10 +140,10 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
136140
// Ensure tip is as expected
137141
BOOST_CHECK_EQUAL(background_cs.m_chain.Tip()->GetBlockHash(), pblockone->GetHash());
138142

139-
// g_best_block should be unchanged after adding a block to the background
143+
// get_notify_tip() should be unchanged after adding a block to the background
140144
// validation chain.
141145
BOOST_CHECK(block_added);
142-
BOOST_CHECK_EQUAL(curr_tip, m_node.notifications->m_tip_block);
146+
BOOST_CHECK_EQUAL(curr_tip, get_notify_tip());
143147
}
144148

145149
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)