Skip to content

Commit

Permalink
validation: replace lock with annotation in UnloadBlockIndex()
Browse files Browse the repository at this point in the history
Summary:
This is a partial backport of [[bitcoin/bitcoin#24299 | core#24299]]
bitcoin/bitcoin@daad009

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D12988
  • Loading branch information
jonatack authored and PiRK committed Jan 18, 2023
1 parent 87635dd commit 7f1cc5f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ ChainTestingSetup::~ChainTestingSetup() {
m_node.banman.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();
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4984,7 +4984,7 @@ void CChainState::UnloadBlockIndex() {
// of the peer-processing logic assumes a consistent
// block index state
void UnloadBlockIndex(CTxMemPool *mempool, ChainstateManager &chainman) {
LOCK(cs_main);
AssertLockHeld(::cs_main);
chainman.Unload();
pindexBestHeader = nullptr;
pindexBestForkTip = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class BlockValidationOptions {
/**
* 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
Expand Down

0 comments on commit 7f1cc5f

Please sign in to comment.