Skip to content

Commit 252a7ae

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 dfbd92f commit 252a7ae

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.
@@ -3416,15 +3402,13 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
34163402
error = _("Failed to rescan the wallet during initialization");
34173403
return false;
34183404
}
3419-
walletInstance->m_attaching_chain = false;
34203405
// Set and update the best block record
34213406
// Although ScanForWalletTransactions will have stopped at the best block that was set prior to the rescan,
34223407
// we still need to make sure that the best block on disk is set correctly as rescanning may overwrite it.
34233408
walletInstance->SetBestBlock(*scan_res.last_scanned_height, scan_res.last_scanned_block);
34243409
}
34253410
walletInstance->GetDatabase().IncrementUpdateCounter();
34263411
}
3427-
walletInstance->m_attaching_chain = false;
34283412

34293413
return true;
34303414
}

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)