Skip to content

Commit e10ca27

Browse files
committed
merge bitcoin#24299: UnloadBlockIndex and ChainstateManager::Reset thread safety cleanups
1 parent 18aa55b commit e10ca27

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,13 +1835,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18351835

18361836
try {
18371837
LOCK(cs_main);
1838+
18381839
node.evodb.reset();
18391840
node.evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
1841+
18401842
node.mnhf_manager.reset();
18411843
node.mnhf_manager = std::make_unique<CMNHFManager>(*node.evodb);
18421844

1843-
1844-
chainman.Reset();
18451845
chainman.InitializeChainstate(Assert(node.mempool.get()), *node.evodb, node.chain_helper, llmq::chainLocksHandler, llmq::quorumInstantSendManager);
18461846
chainman.m_total_coinstip_cache = nCoinCacheUsage;
18471847
chainman.m_total_coinsdb_cache = nCoinDBCache;

src/test/util/setup_common.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,9 @@ ChainTestingSetup::~ChainTestingSetup()
254254
m_node.connman.reset();
255255
m_node.addrman.reset();
256256
m_node.args = nullptr;
257-
UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman);
257+
WITH_LOCK(::cs_main, UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman));
258258
m_node.mempool.reset();
259259
m_node.scheduler.reset();
260-
m_node.chainman->Reset();
261260
m_node.chainman.reset();
262261
}
263262

src/validation.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4375,7 +4375,7 @@ void CChainState::UnloadBlockIndex()
43754375
// block index state
43764376
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
43774377
{
4378-
LOCK(cs_main);
4378+
AssertLockHeld(::cs_main);
43794379
chainman.Unload();
43804380
if (mempool) mempool->clear();
43814381
g_versionbitscache.Clear();
@@ -5468,15 +5468,6 @@ void ChainstateManager::Unload()
54685468
m_best_invalid = nullptr;
54695469
}
54705470

5471-
void ChainstateManager::Reset()
5472-
{
5473-
LOCK(::cs_main);
5474-
m_ibd_chainstate.reset();
5475-
m_snapshot_chainstate.reset();
5476-
m_active_chainstate = nullptr;
5477-
m_snapshot_validated = false;
5478-
}
5479-
54805471
void ChainstateManager::MaybeRebalanceCaches()
54815472
{
54825473
AssertLockHeld(::cs_main);

src/validation.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ extern arith_uint256 nMinimumChainWork;
152152
extern const std::vector<std::string> CHECKLEVEL_DOC;
153153

154154
/** Unload database information */
155-
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman);
155+
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
156156
/** Run instances of script checking worker threads */
157157
void StartScriptCheckWorkerThreads(int threads_num);
158158
/** Stop all of the script checking worker threads */
@@ -1003,17 +1003,13 @@ class ChainstateManager
10031003
//! Unload block index and chain data before shutdown.
10041004
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
10051005

1006-
//! Clear (deconstruct) chainstate data.
1007-
void Reset();
1008-
10091006
//! Check to see if caches are out of balance and if so, call
10101007
//! ResizeCoinsCaches() as needed.
10111008
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
10121009

10131010
~ChainstateManager() {
10141011
LOCK(::cs_main);
1015-
UnloadBlockIndex(/* mempool */ nullptr, *this);
1016-
Reset();
1012+
UnloadBlockIndex(/*mempool=*/nullptr, *this);
10171013
}
10181014
};
10191015

0 commit comments

Comments
 (0)