Skip to content

Commit 98a1a52

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 7fd3e1c commit 98a1a52

File tree

3 files changed

+0
-26
lines changed

3 files changed

+0
-26
lines changed

src/bench/wallet_migration.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ static void WalletMigration(benchmark::Bench& bench)
2828

2929
// Setup legacy wallet
3030
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase());
31-
wallet->chainStateFlushed(ChainstateRole::NORMAL, CBlockLocator{});
3231
LegacyDataSPKM* legacy_spkm = wallet->GetOrCreateLegacyDataSPKM();
3332
WalletBatch batch{wallet->GetDatabase()};
3433

src/wallet/wallet.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,6 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
652652
return false;
653653
}
654654

655-
void CWallet::chainStateFlushed(ChainstateRole role, const CBlockLocator& loc)
656-
{
657-
// Don't update the best block until the chain is attached so that in case of a shutdown,
658-
// the rescan will be restarted at next startup.
659-
if (m_attaching_chain || role == ChainstateRole::BACKGROUND) {
660-
return;
661-
}
662-
WalletBatch batch(GetDatabase());
663-
batch.WriteBestBlock(loc);
664-
}
665-
666655
void CWallet::SetLastBlockProcessedInMem(int block_height, uint256 block_hash)
667656
{
668657
AssertLockHeld(cs_wallet);
@@ -3143,11 +3132,6 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
31433132
// be pending on the validation-side until lock release. Blocks that are connected while the
31443133
// rescan is ongoing will not be processed in the rescan but with the block connected notifications,
31453134
// so the wallet will only be completeley synced after the notifications delivery.
3146-
// chainStateFlushed notifications are ignored until the rescan is finished
3147-
// so that in case of a shutdown event, the rescan will be repeated at the next start.
3148-
// This is temporary until rescan and notifications delivery are unified under same
3149-
// interface.
3150-
walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
31513135
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
31523136

31533137
// If rescan_required = true, rescan_height remains equal to 0
@@ -3233,14 +3217,12 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
32333217
error = _("Failed to rescan the wallet during initialization");
32343218
return false;
32353219
}
3236-
walletInstance->m_attaching_chain = false;
32373220
// Set and update the best block record
32383221
// Set last block scanned as the last block processed as it may be different in case the case of a reorg.
32393222
// Also save the best block locator because rescanning only updates it intermittently.
32403223
walletInstance->SetLastBlockProcessed(*scan_res.last_scanned_height, scan_res.last_scanned_block);
32413224
}
32423225
}
3243-
walletInstance->m_attaching_chain = false;
32443226

32453227
return true;
32463228
}
@@ -4229,11 +4211,6 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
42294211
return util::Error{_("Error: This wallet is already a descriptor wallet")};
42304212
}
42314213

4232-
// Flush chain state before unloading wallet
4233-
CBlockLocator locator;
4234-
WITH_LOCK(wallet->cs_wallet, context.chain->findBlock(wallet->GetLastBlockHash(), FoundBlock().locator(locator)));
4235-
if (!locator.IsNull()) wallet->chainStateFlushed(ChainstateRole::NORMAL, locator);
4236-
42374214
if (!RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt, warnings)) {
42384215
return util::Error{_("Unable to unload the wallet before migrating")};
42394216
}

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
305305

306306
std::atomic<bool> fAbortRescan{false};
307307
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
308-
std::atomic<bool> m_attaching_chain{false};
309308
std::atomic<bool> m_scanning_with_passphrase{false};
310309
std::atomic<SteadyClock::time_point> m_scanning_start{SteadyClock::time_point{}};
311310
std::atomic<double> m_scanning_progress{0};
@@ -787,7 +786,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
787786
/** should probably be renamed to IsRelevantToMe */
788787
bool IsFromMe(const CTransaction& tx) const;
789788
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
790-
void chainStateFlushed(ChainstateRole role, const CBlockLocator& loc) override;
791789

792790
DBErrors LoadWallet();
793791

0 commit comments

Comments
 (0)