Skip to content

Commit cba41db

Browse files
committed
Merge bitcoin/bitcoin#24299: validation, refactor: UnloadBlockIndex and ChainstateManager::Reset thread safety cleanups
ae9ceed validation, refactoring: remove ChainstateManager::Reset() (Jon Atack) daad009 validation: replace lock with annotation in UnloadBlockIndex() (Jon Atack) Pull request description: Thread safety refactoring seen in #24177: - replace re-acquiring lock cs_main with a thread safety annotation in UnloadBlockIndex() - remove ChainstateManager::Reset(), as it is currently unused (can be reintroduced in the test utilities if needed for unit testing) ACKs for top commit: laanwj: Code review ACK ae9ceed vasild: ACK ae9ceed klementtan: crACK ae9ceed Tree-SHA512: cebb782572997cc2dda01590d6bb6c5e479e8202324d8b6ff459b814ce09e818b996c881736bfebd1b8bf4b6d7a0f79faf3ffea176a4699dd7d7429de2db2d13
2 parents f6d335e + ae9ceed commit cba41db

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

src/test/util/setup_common.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ ChainTestingSetup::~ChainTestingSetup()
180180
m_node.banman.reset();
181181
m_node.addrman.reset();
182182
m_node.args = nullptr;
183-
UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman);
183+
WITH_LOCK(::cs_main, UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman));
184184
m_node.mempool.reset();
185185
m_node.scheduler.reset();
186-
m_node.chainman->Reset();
187186
m_node.chainman.reset();
188187
}
189188

src/validation.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,7 +4070,7 @@ void CChainState::UnloadBlockIndex()
40704070
// block index state
40714071
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
40724072
{
4073-
LOCK(cs_main);
4073+
AssertLockHeld(::cs_main);
40744074
chainman.Unload();
40754075
pindexBestHeader = nullptr;
40764076
if (mempool) mempool->clear();
@@ -5056,15 +5056,6 @@ void ChainstateManager::Unload()
50565056
m_best_invalid = nullptr;
50575057
}
50585058

5059-
void ChainstateManager::Reset()
5060-
{
5061-
LOCK(::cs_main);
5062-
m_ibd_chainstate.reset();
5063-
m_snapshot_chainstate.reset();
5064-
m_active_chainstate = nullptr;
5065-
m_snapshot_validated = false;
5066-
}
5067-
50685059
void ChainstateManager::MaybeRebalanceCaches()
50695060
{
50705061
AssertLockHeld(::cs_main);

src/validation.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extern CBlockIndex *pindexBestHeader;
138138
extern const std::vector<std::string> CHECKLEVEL_DOC;
139139

140140
/** Unload database information */
141-
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman);
141+
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
142142
/** Run instances of script checking worker threads */
143143
void StartScriptCheckWorkerThreads(int threads_num);
144144
/** Stop all of the script checking worker threads */
@@ -991,17 +991,13 @@ class ChainstateManager
991991
//! Unload block index and chain data before shutdown.
992992
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
993993

994-
//! Clear (deconstruct) chainstate data.
995-
void Reset();
996-
997994
//! Check to see if caches are out of balance and if so, call
998995
//! ResizeCoinsCaches() as needed.
999996
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1000997

1001998
~ChainstateManager() {
1002999
LOCK(::cs_main);
1003-
UnloadBlockIndex(/* mempool */ nullptr, *this);
1004-
Reset();
1000+
UnloadBlockIndex(/*mempool=*/nullptr, *this);
10051001
}
10061002
};
10071003

0 commit comments

Comments
 (0)