From ba10b90915dae6a802ecb0f80f72a1a9ea5a4c67 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Mon, 9 May 2022 01:54:16 +0000 Subject: [PATCH] Wallet: Ensure m_attaching_chain is set before registering for signals Avoids a race where chainStateFlushed could be called before rescanning began, yet rescan gets interrupted or fails --- src/wallet/wallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 356d0ce5a05..0c247998fe6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2961,6 +2961,7 @@ bool CWallet::AttachChain(const std::shared_ptr& walletInstance, interf // so that in case of a shutdown event, the rescan will be repeated at the next start. // This is temporary until rescan and notifications delivery are unified under same // interface. + walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance); // If rescan_required = true, rescan_height remains equal to 0 @@ -2987,7 +2988,6 @@ bool CWallet::AttachChain(const std::shared_ptr& walletInstance, interf if (tip_height && *tip_height != rescan_height) { - walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications if (chain.havePruned()) { int block_height = *tip_height; while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_height) { @@ -3031,6 +3031,7 @@ bool CWallet::AttachChain(const std::shared_ptr& walletInstance, interf walletInstance->chainStateFlushed(chain.getTipLocator()); walletInstance->GetDatabase().IncrementUpdateCounter(); } + walletInstance->m_attaching_chain = false; return true; }