From 31c0df038909e40fe9618a4595254907ed1de907 Mon Sep 17 00:00:00 2001 From: furszy Date: Mon, 26 Aug 2024 10:35:53 -0300 Subject: [PATCH] wallet: migration, write best locator before unloading wallet --- src/wallet/wallet.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ff3f45b6d0c..b921bc5e491 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4398,6 +4398,11 @@ util::Result MigrateLegacyToDescriptor(const std::string& walle return util::Error{_("Error: This wallet is already a descriptor wallet")}; } + // Flush chain state before unloading wallet + CBlockLocator locator; + WITH_LOCK(wallet->cs_wallet, context.chain->findBlock(wallet->GetLastBlockHash(), FoundBlock().locator(locator))); + if (!locator.IsNull()) wallet->chainStateFlushed(ChainstateRole::NORMAL, locator); + if (!RemoveWallet(context, wallet, /*load_on_start=*/std::nullopt, warnings)) { return util::Error{_("Unable to unload the wallet before migrating")}; }