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
This commit is contained in:
Luke Dashjr
2022-05-09 01:54:16 +00:00
parent 59ac8bacd5
commit ba10b90915

View File

@@ -2961,6 +2961,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& 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<CWallet>& 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<CWallet>& walletInstance, interf
walletInstance->chainStateFlushed(chain.getTipLocator());
walletInstance->GetDatabase().IncrementUpdateCounter();
}
walletInstance->m_attaching_chain = false;
return true;
}