Skip to content

Commit bef4b1f

Browse files
furszyfanquake
authored andcommitted
wallet: improve post-migration logging
Right now, after migration the last message users see is "migration completed", but the migration isn't actually finished yet. We still need to load the new wallets to ensure consistency, and if that fails, the migration will be rolled back. This can be confusing for users. This change logs the post-migration loading step and if a wallet fails to load and the migration will be rolled back. Github-Pull: #34156 Rebased-From: d70b159
1 parent ac940ac commit bef4b1f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,6 +4356,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
43564356
for (const auto& path_to_remove : paths_to_remove) fs::remove(path_to_remove);
43574357
}
43584358

4359+
LogInfo("Loading new wallets after migration...\n");
43594360
// Migration successful, load all the migrated wallets.
43604361
for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet, &res.solvables_wallet}) {
43614362
if (success && *wallet_ptr) {
@@ -4366,10 +4367,16 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
43664367
std::string wallet_name = wallet->GetName();
43674368
wallet.reset();
43684369
wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
4369-
success = (wallet != nullptr);
4370+
if (!wallet) {
4371+
LogError("Failed to load wallet '%s' after migration. Rolling back migration to preserve consistency. "
4372+
"Error cause: %s\n", wallet_name, error.original);
4373+
success = false;
4374+
break;
4375+
}
43704376

4371-
// When no wallet is set, set the main wallet.
4372-
if (success && !res.wallet) {
4377+
// Set the first successfully loaded wallet as the main one.
4378+
// The loop order is intentional and must always start with the local wallet.
4379+
if (!res.wallet) {
43734380
res.wallet_name = wallet->GetName();
43744381
res.wallet = std::move(wallet);
43754382
}

0 commit comments

Comments
 (0)