Skip to content

Commit 6cdac90

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 d2efbbf commit 6cdac90

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
@@ -642,15 +642,6 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
642642
return false;
643643
}
644644

645-
void CWallet::chainStateFlushed(ChainstateRole role, const CBlockLocator& loc)
646-
{
647-
// Don't update the best block until the chain is attached so that in case of a shutdown,
648-
// the rescan will be restarted at next startup.
649-
if (m_attaching_chain || role == ChainstateRole::BACKGROUND) {
650-
return;
651-
}
652-
}
653-
654645
void CWallet::SetBestBlock(int block_height, uint256 block_hash)
655646
{
656647
AssertLockHeld(cs_wallet);
@@ -3268,11 +3259,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
32683259
// be pending on the validation-side until lock release. It's likely to have
32693260
// block processing duplicata (if rescan block range overlaps with notification one)
32703261
// but we guarantee at least than wallet state is correct after notifications delivery.
3271-
// However, chainStateFlushed notifications are ignored until the rescan is finished
3272-
// so that in case of a shutdown event, the rescan will be repeated at the next start.
3273-
// This is temporary until rescan and notifications delivery are unified under same
3274-
// interface.
3275-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
32763262
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
32773263

32783264
const std::optional<int> tip_height = chain.getHeight();
@@ -3360,13 +3346,11 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
33603346
error = _("Failed to rescan the wallet during initialization");
33613347
return false;
33623348
}
3363-
walletInstance->m_attaching_chain = false;
33643349
// Set and update the best block record
33653350
walletInstance->SetBestBlock(*scan_res.last_scanned_height, scan_res.last_scanned_block);
33663351
}
33673352
walletInstance->GetDatabase().IncrementUpdateCounter();
33683353
}
3369-
walletInstance->m_attaching_chain = false;
33703354

33713355
return true;
33723356
}

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};
@@ -809,7 +808,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
809808
/** should probably be renamed to IsRelevantToMe */
810809
bool IsFromMe(const CTransaction& tx) const;
811810
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
812-
void chainStateFlushed(ChainstateRole role, const CBlockLocator& loc) override;
813811

814812
DBErrors LoadWallet();
815813

0 commit comments

Comments
 (0)