mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 03:53:22 +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.
|
// 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
|
// This is temporary until rescan and notifications delivery are unified under same
|
||||||
// interface.
|
// interface.
|
||||||
|
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
|
||||||
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
|
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
|
||||||
|
|
||||||
// If rescan_required = true, rescan_height remains equal to 0
|
// 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)
|
if (tip_height && *tip_height != rescan_height)
|
||||||
{
|
{
|
||||||
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
|
|
||||||
if (chain.havePruned()) {
|
if (chain.havePruned()) {
|
||||||
int block_height = *tip_height;
|
int block_height = *tip_height;
|
||||||
while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_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->chainStateFlushed(chain.getTipLocator());
|
||||||
walletInstance->GetDatabase().IncrementUpdateCounter();
|
walletInstance->GetDatabase().IncrementUpdateCounter();
|
||||||
}
|
}
|
||||||
|
walletInstance->m_attaching_chain = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user