mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 07:39:08 +01:00
refactor: consolidate 3 separate locks into one block
The main lock needs to be taken 3 separate times. It simplifies readability to take it once, and is more efficient.
This commit is contained in:
@@ -3560,19 +3560,24 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
|
||||
} // release cs_main
|
||||
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
||||
|
||||
if (exited_ibd) {
|
||||
// If a background chainstate is in use, we may need to rebalance our
|
||||
// allocation of caches once a chainstate exits initial block download.
|
||||
LOCK(::cs_main);
|
||||
m_chainman.MaybeRebalanceCaches();
|
||||
bool disabled{false};
|
||||
{
|
||||
LOCK(m_chainman.GetMutex());
|
||||
if (exited_ibd) {
|
||||
// If a background chainstate is in use, we may need to rebalance our
|
||||
// allocation of caches once a chainstate exits initial block download.
|
||||
m_chainman.MaybeRebalanceCaches();
|
||||
}
|
||||
|
||||
// Write changes periodically to disk, after relay.
|
||||
if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
disabled = m_disabled;
|
||||
}
|
||||
|
||||
// Write changes periodically to disk, after relay.
|
||||
if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (WITH_LOCK(::cs_main, return m_disabled)) {
|
||||
if (disabled) {
|
||||
// Background chainstate has reached the snapshot base block, so exit.
|
||||
|
||||
// Restart indexes to resume indexing for all blocks unique to the snapshot
|
||||
|
||||
Reference in New Issue
Block a user