Skip to content

Commit

Permalink
Merge bitcoin#25088: Wallet: Ensure m_attaching_chain is set before r…
Browse files Browse the repository at this point in the history
…egistering 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
  • Loading branch information
achow101 authored and PastaPastaPasta committed Aug 14, 2024
1 parent 5b60c78 commit c29aff4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4998,6 +4998,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);

int rescan_height = 0;
Expand All @@ -5023,7 +5024,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) {
Expand Down Expand Up @@ -5070,6 +5070,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;
}
Expand Down

0 comments on commit c29aff4

Please sign in to comment.