Skip to content

Commit bcb8f3e

Browse files
committed
wallet: Remove chainStateFlushed
chainStateFlushed is no longer needed since the best block is updated after a block is scanned. Since the chainstate being flushed does not necessarily coincide with the wallet having processed said block, it does not entirely make sense for the wallet to be recording that block as its best block, and this can cause race conditions where some blocks are not processed. Thus, remove this notification.
1 parent 30407a0 commit bcb8f3e

File tree

2 files changed

+0
-18
lines changed

2 files changed

+0
-18
lines changed

src/wallet/wallet.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,6 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
652652
return false;
653653
}
654654

655-
void CWallet::chainStateFlushed(ChainstateRole role, const CBlockLocator& loc)
656-
{
657-
// Don't update the best block until the chain is attached so that in case of a shutdown,
658-
// the rescan will be restarted at next startup.
659-
if (m_attaching_chain || role == ChainstateRole::BACKGROUND) {
660-
return;
661-
}
662-
}
663-
664655
void CWallet::SetBestBlockInMem(int block_height, uint256 block_hash)
665656
{
666657
AssertLockHeld(cs_wallet);
@@ -3324,11 +3315,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
33243315
// be pending on the validation-side until lock release. Blocks that are connected while the
33253316
// rescan is ongoing will not be processed in the rescan but with the block connected notifications,
33263317
// so the wallet will only be completeley synced after the notifications delivery.
3327-
// chainStateFlushed notifications are ignored until the rescan is finished
3328-
// so that in case of a shutdown event, the rescan will be repeated at the next start.
3329-
// This is temporary until rescan and notifications delivery are unified under same
3330-
// interface.
3331-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
33323318
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
33333319

33343320
// Update the best block locator if it is missing the height.
@@ -3418,15 +3404,13 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
34183404
error = _("Failed to rescan the wallet during initialization");
34193405
return false;
34203406
}
3421-
walletInstance->m_attaching_chain = false;
34223407
// Set and update the best block record
34233408
// Although ScanForWalletTransactions will have stopped at the best block that was set prior to the rescan,
34243409
// we still need to make sure that the best block on disk is set correctly as rescanning may overwrite it.
34253410
walletInstance->SetBestBlock(*scan_res.last_scanned_height, scan_res.last_scanned_block);
34263411
}
34273412
walletInstance->GetDatabase().IncrementUpdateCounter();
34283413
}
3429-
walletInstance->m_attaching_chain = false;
34303414

34313415
return true;
34323416
}

src/wallet/wallet.h

-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
338338

339339
std::atomic<bool> fAbortRescan{false};
340340
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
341-
std::atomic<bool> m_attaching_chain{false};
342341
std::atomic<bool> m_scanning_with_passphrase{false};
343342
std::atomic<SteadyClock::time_point> m_scanning_start{SteadyClock::time_point{}};
344343
std::atomic<double> m_scanning_progress{0};
@@ -815,7 +814,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
815814
/** should probably be renamed to IsRelevantToMe */
816815
bool IsFromMe(const CTransaction& tx) const;
817816
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
818-
void chainStateFlushed(ChainstateRole role, const CBlockLocator& loc) override;
819817

820818
DBErrors LoadWallet();
821819

0 commit comments

Comments
 (0)