From 84820561dcb2d156d1a1151a480fc1be6649cae4 Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Sat, 3 May 2025 08:41:02 -0400 Subject: [PATCH] validation: periodically flush dbcache during reindex-chainstate Move the periodic flush inside the outer loop of ActivateBestChain. For very long activations, such as with reindex-chainstate, this calls periodic flushes so progress can be saved to disk. Co-Authored-By: l0rinc --- src/validation.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 5ad2ebdcd7e..94b9de3a49e 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3567,6 +3567,11 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< m_chainman.MaybeRebalanceCaches(); } + // Write changes periodically to disk, after relay. + if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) { + return false; + } + if (WITH_LOCK(::cs_main, return m_disabled)) { // Background chainstate has reached the snapshot base block, so exit. @@ -3591,11 +3596,6 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< m_chainman.CheckBlockIndex(); - // Write changes periodically to disk, after relay. - if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) { - return false; - } - return true; }