Skip to content

Commit eecaca1

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 b7c631e commit eecaca1

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);
@@ -3325,11 +3316,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
33253316
// be pending on the validation-side until lock release. Blocks that are connected while the
33263317
// rescan is ongoing will not be processed in the rescan but with the block connected notifications,
33273318
// so the wallet will only be completeley synced after the notifications delivery.
3328-
// chainStateFlushed notifications are ignored until the rescan is finished
3329-
// so that in case of a shutdown event, the rescan will be repeated at the next start.
3330-
// This is temporary until rescan and notifications delivery are unified under same
3331-
// interface.
3332-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
33333319
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
33343320

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

34333417
return true;
34343418
}

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)