Skip to content

Commit ba10b90

Browse files
committed
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
1 parent 59ac8ba commit ba10b90

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
29612961
// so that in case of a shutdown event, the rescan will be repeated at the next start.
29622962
// This is temporary until rescan and notifications delivery are unified under same
29632963
// interface.
2964+
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
29642965
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
29652966

29662967
// If rescan_required = true, rescan_height remains equal to 0
@@ -2987,7 +2988,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
29872988

29882989
if (tip_height && *tip_height != rescan_height)
29892990
{
2990-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
29912991
if (chain.havePruned()) {
29922992
int block_height = *tip_height;
29932993
while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_height) {
@@ -3031,6 +3031,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
30313031
walletInstance->chainStateFlushed(chain.getTipLocator());
30323032
walletInstance->GetDatabase().IncrementUpdateCounter();
30333033
}
3034+
walletInstance->m_attaching_chain = false;
30343035

30353036
return true;
30363037
}

0 commit comments

Comments
 (0)