Skip to content

Commit d71fb90

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 810bc51 commit d71fb90

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
@@ -648,15 +648,6 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
648648
return false;
649649
}
650650

651-
void CWallet::chainStateFlushed(ChainstateRole role, const CBlockLocator& loc)
652-
{
653-
// Don't update the best block until the chain is attached so that in case of a shutdown,
654-
// the rescan will be restarted at next startup.
655-
if (m_attaching_chain || role == ChainstateRole::BACKGROUND) {
656-
return;
657-
}
658-
}
659-
660651
void CWallet::SetBestBlockInMem(int block_height, uint256 block_hash)
661652
{
662653
AssertLockHeld(cs_wallet);
@@ -3320,11 +3311,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
33203311
// be pending on the validation-side until lock release. Blocks that are connected while the
33213312
// rescan is ongoing will not be processed in the rescan but with the block connected notifications,
33223313
// so the wallet will only be completeley synced after the notifications delivery.
3323-
// chainStateFlushed notifications are ignored until the rescan is finished
3324-
// so that in case of a shutdown event, the rescan will be repeated at the next start.
3325-
// This is temporary until rescan and notifications delivery are unified under same
3326-
// interface.
3327-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
33283314
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
33293315

33303316
// Update the best block locator if it is missing the height.
@@ -3414,15 +3400,13 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
34143400
error = _("Failed to rescan the wallet during initialization");
34153401
return false;
34163402
}
3417-
walletInstance->m_attaching_chain = false;
34183403
// Set and update the best block record
34193404
// Although ScanForWalletTransactions will have stopped at the best block that was set prior to the rescan,
34203405
// we still need to make sure that the best block on disk is set correctly as rescanning may overwrite it.
34213406
walletInstance->SetBestBlock(*scan_res.last_scanned_height, scan_res.last_scanned_block);
34223407
}
34233408
walletInstance->GetDatabase().IncrementUpdateCounter();
34243409
}
3425-
walletInstance->m_attaching_chain = false;
34263410

34273411
return true;
34283412
}

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)