merge bitcoin#24299: UnloadBlockIndex and ChainstateManager::Reset thread safety cleanups

This commit is contained in:
Kittywhiskers Van Gogh 2024-07-04 14:19:21 +00:00
parent 18aa55be1e
commit e10ca27fa6
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
4 changed files with 6 additions and 20 deletions

View File

@ -1835,13 +1835,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
try {
LOCK(cs_main);
node.evodb.reset();
node.evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
node.mnhf_manager.reset();
node.mnhf_manager = std::make_unique<CMNHFManager>(*node.evodb);
chainman.Reset();
chainman.InitializeChainstate(Assert(node.mempool.get()), *node.evodb, node.chain_helper, llmq::chainLocksHandler, llmq::quorumInstantSendManager);
chainman.m_total_coinstip_cache = nCoinCacheUsage;
chainman.m_total_coinsdb_cache = nCoinDBCache;

View File

@ -254,10 +254,9 @@ ChainTestingSetup::~ChainTestingSetup()
m_node.connman.reset();
m_node.addrman.reset();
m_node.args = nullptr;
UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman);
WITH_LOCK(::cs_main, UnloadBlockIndex(m_node.mempool.get(), *m_node.chainman));
m_node.mempool.reset();
m_node.scheduler.reset();
m_node.chainman->Reset();
m_node.chainman.reset();
}

View File

@ -4375,7 +4375,7 @@ void CChainState::UnloadBlockIndex()
// block index state
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
{
LOCK(cs_main);
AssertLockHeld(::cs_main);
chainman.Unload();
if (mempool) mempool->clear();
g_versionbitscache.Clear();
@ -5468,15 +5468,6 @@ void ChainstateManager::Unload()
m_best_invalid = nullptr;
}
void ChainstateManager::Reset()
{
LOCK(::cs_main);
m_ibd_chainstate.reset();
m_snapshot_chainstate.reset();
m_active_chainstate = nullptr;
m_snapshot_validated = false;
}
void ChainstateManager::MaybeRebalanceCaches()
{
AssertLockHeld(::cs_main);

View File

@ -152,7 +152,7 @@ extern arith_uint256 nMinimumChainWork;
extern const std::vector<std::string> CHECKLEVEL_DOC;
/** Unload database information */
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman);
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/** Run instances of script checking worker threads */
void StartScriptCheckWorkerThreads(int threads_num);
/** Stop all of the script checking worker threads */
@ -1003,17 +1003,13 @@ public:
//! Unload block index and chain data before shutdown.
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
//! Clear (deconstruct) chainstate data.
void Reset();
//! Check to see if caches are out of balance and if so, call
//! ResizeCoinsCaches() as needed.
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
~ChainstateManager() {
LOCK(::cs_main);
UnloadBlockIndex(/* mempool */ nullptr, *this);
Reset();
UnloadBlockIndex(/*mempool=*/nullptr, *this);
}
};