mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Merge bitcoin/bitcoin#24299: validation, refactor: UnloadBlockIndex and ChainstateManager::Reset thread safety cleanups
ae9ceed3e2validation, refactoring: remove ChainstateManager::Reset() (Jon Atack)daad0093e3validation: 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 ACKae9ceed3e2vasild: ACKae9ceed3e2klementtan: crACKae9ceed3e2Tree-SHA512: cebb782572997cc2dda01590d6bb6c5e479e8202324d8b6ff459b814ce09e818b996c881736bfebd1b8bf4b6d7a0f79faf3ffea176a4699dd7d7429de2db2d13
This commit is contained in:
commit
cba41db327
3 changed files with 4 additions and 18 deletions
|
|
@ -180,10 +180,9 @@ ChainTestingSetup::~ChainTestingSetup()
|
||||||
m_node.banman.reset();
|
m_node.banman.reset();
|
||||||
m_node.addrman.reset();
|
m_node.addrman.reset();
|
||||||
m_node.args = nullptr;
|
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.mempool.reset();
|
||||||
m_node.scheduler.reset();
|
m_node.scheduler.reset();
|
||||||
m_node.chainman->Reset();
|
|
||||||
m_node.chainman.reset();
|
m_node.chainman.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4070,7 +4070,7 @@ void CChainState::UnloadBlockIndex()
|
||||||
// block index state
|
// block index state
|
||||||
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
|
void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
AssertLockHeld(::cs_main);
|
||||||
chainman.Unload();
|
chainman.Unload();
|
||||||
pindexBestHeader = nullptr;
|
pindexBestHeader = nullptr;
|
||||||
if (mempool) mempool->clear();
|
if (mempool) mempool->clear();
|
||||||
|
|
@ -5056,15 +5056,6 @@ void ChainstateManager::Unload()
|
||||||
m_best_invalid = nullptr;
|
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()
|
void ChainstateManager::MaybeRebalanceCaches()
|
||||||
{
|
{
|
||||||
AssertLockHeld(::cs_main);
|
AssertLockHeld(::cs_main);
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ extern CBlockIndex *pindexBestHeader;
|
||||||
extern const std::vector<std::string> CHECKLEVEL_DOC;
|
extern const std::vector<std::string> CHECKLEVEL_DOC;
|
||||||
|
|
||||||
/** Unload database information */
|
/** 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 */
|
/** Run instances of script checking worker threads */
|
||||||
void StartScriptCheckWorkerThreads(int threads_num);
|
void StartScriptCheckWorkerThreads(int threads_num);
|
||||||
/** Stop all of the script checking worker threads */
|
/** Stop all of the script checking worker threads */
|
||||||
|
|
@ -991,17 +991,13 @@ public:
|
||||||
//! Unload block index and chain data before shutdown.
|
//! Unload block index and chain data before shutdown.
|
||||||
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
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
|
//! Check to see if caches are out of balance and if so, call
|
||||||
//! ResizeCoinsCaches() as needed.
|
//! ResizeCoinsCaches() as needed.
|
||||||
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
~ChainstateManager() {
|
~ChainstateManager() {
|
||||||
LOCK(::cs_main);
|
LOCK(::cs_main);
|
||||||
UnloadBlockIndex(/* mempool */ nullptr, *this);
|
UnloadBlockIndex(/*mempool=*/nullptr, *this);
|
||||||
Reset();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue