Skip to content

Commit d70b159

Browse files
committed
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.
1 parent f011e0f commit d70b159

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
@@ -4366,6 +4366,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
43664366
for (const auto& path_to_remove : paths_to_remove) fs::remove(path_to_remove);
43674367
}
43684368

4369+
LogInfo("Loading new wallets after migration...\n");
43694370
// Migration successful, load all the migrated wallets.
43704371
for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet, &res.solvables_wallet}) {
43714372
if (success && *wallet_ptr) {
@@ -4376,10 +4377,16 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
43764377
std::string wallet_name = wallet->GetName();
43774378
wallet.reset();
43784379
wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
4379-
success = (wallet != nullptr);
4380+
if (!wallet) {
4381+
LogError("Failed to load wallet '%s' after migration. Rolling back migration to preserve consistency. "
4382+
"Error cause: %s\n", wallet_name, error.original);
4383+
success = false;
4384+
break;
4385+
}
43804386

4381-
// When no wallet is set, set the main wallet.
4382-
if (success && !res.wallet) {
4387+
// Set the first successfully loaded wallet as the main one.
4388+
// The loop order is intentional and must always start with the local wallet.
4389+
if (!res.wallet) {
43834390
res.wallet_name = wallet->GetName();
43844391
res.wallet = std::move(wallet);
43854392
}

0 commit comments

Comments
 (0)