Skip to content

Commit ce95fb3

Browse files
ryanofskydongcarl
andcommitted
Remove cs_main lock annotation from ChainstateManager.m_blockman
BlockManager is a large data structure, and cs_main is not required to take its address or access every part of it. Individual BlockManager fields and methods which do require cs_main like m_block_index and LookupBlockIndex are already annotated separately, and these other annotations describe locking requirements more accurately and do a better job enforcing thread safety. Since cs_main is not needed to access the address of the m_block object, this commit drops cs_main LOCK calls which were added pointlessly to satisfy this annotation in the past. Co-authored-by: Carl Dong <[email protected]>
1 parent c561f2f commit ce95fb3

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/test/fuzz/coins_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
273273
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
274274
bool expected_code_path = false;
275275
try {
276-
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_setup->m_node.chainman->m_blockman)), stats);
276+
(void)GetUTXOStats(&coins_view_cache, g_setup->m_node.chainman->m_blockman, stats);
277277
} catch (const std::logic_error&) {
278278
expected_code_path = true;
279279
}

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4873,7 +4873,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
48734873
// about the snapshot_chainstate.
48744874
CCoinsViewDB* snapshot_coinsdb = WITH_LOCK(::cs_main, return &snapshot_chainstate.CoinsDB());
48754875

4876-
if (!GetUTXOStats(snapshot_coinsdb, WITH_LOCK(::cs_main, return std::ref(m_blockman)), stats, breakpoint_fnc)) {
4876+
if (!GetUTXOStats(snapshot_coinsdb, m_blockman, stats, breakpoint_fnc)) {
48774877
LogPrintf("[snapshot] failed to generate coins stats\n");
48784878
return false;
48794879
}

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ class ChainstateManager
828828
std::thread m_load_block;
829829
//! A single BlockManager instance is shared across each constructed
830830
//! chainstate to avoid duplicating block metadata.
831-
node::BlockManager m_blockman GUARDED_BY(::cs_main);
831+
node::BlockManager m_blockman;
832832

833833
/**
834834
* In order to efficiently track invalidity of headers, we keep the set of

0 commit comments

Comments
 (0)