Skip to content

Commit e5ed423

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 7e46a8b commit e5ed423

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

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

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

34283412
return true;
34293413
}

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)