mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#24299: UnloadBlockIndex and ChainstateManager::Reset thread safety cleanups
This commit is contained in:
parent
18aa55be1e
commit
e10ca27fa6
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user