Skip to content

Commit 98f4db3

Browse files
committed
Merge bitcoin#25088: Wallet: Ensure m_attaching_chain is set before registering for signals
ba10b90 Wallet: Ensure m_attaching_chain is set before registering for signals (Luke Dashjr) Pull request description: Avoids a race where chainStateFlushed could be called before rescanning began, yet rescan gets interrupted or fails Followup for bitcoin#24984 avoiding a race between registering and setting the flag. ACKs for top commit: mzumsande: Code Review ACK ba10b90 achow101: ACK ba10b90 Tree-SHA512: 1d2fa2db189d3e87f2d0863cf2ab62166094436483f0da16760b1083a4743bf08e476a3277e0d36564213d65dd6f0a1fc16a4bf68d3338c991a14d1de9fc0fee
2 parents 187504b + ba10b90 commit 98f4db3

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
@@ -2964,6 +2964,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
29642964
// so that in case of a shutdown event, the rescan will be repeated at the next start.
29652965
// This is temporary until rescan and notifications delivery are unified under same
29662966
// interface.
2967+
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
29672968
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
29682969

29692970
// If rescan_required = true, rescan_height remains equal to 0
@@ -2990,7 +2991,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
29902991

29912992
if (tip_height && *tip_height != rescan_height)
29922993
{
2993-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
29942994
if (chain.havePruned()) {
29952995
int block_height = *tip_height;
29962996
while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_height) {
@@ -3034,6 +3034,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
30343034
walletInstance->chainStateFlushed(chain.getTipLocator());
30353035
walletInstance->GetDatabase().IncrementUpdateCounter();
30363036
}
3037+
walletInstance->m_attaching_chain = false;
30373038

30383039
return true;
30393040
}

0 commit comments

Comments
 (0)