mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-03 11:53:16 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user