wallet: improve post-migration logging
What changed, and why it matters
This commit only improves user-facing log messages during Bitcoin Core's wallet migration process. It adds a message saying the new wallets are being loaded after migration, and another message if a wallet fails to load and the migration must be rolled back. There is no security fix or behavior change beyond clearer logging.
No security action required. Treat as a normal quality-of-life logging improvement.
Security signals we found
No security-relevant code change
Logging-only improvement
No change to migration or rollback logic semantics
Evidence from the diff
The change modifies MigrateLegacyToDescriptor in src/wallet/wallet.cpp to add LogInfo/LogError calls and slightly restructure the success-handling logic. The functional behavior remains the same: after a successful legacy-to-descriptor migration, the code still loads each migrated wallet and sets success=false if any load fails. The only differences are (1) an informational log before loading, (2) an explicit error log with the wallet name and error cause on load failure, and (3) a break out of the loop once a failure occurs rather than continuing to iterate. The rollback behavior already existed; it is now better logged.
Changed components
src/wallet/wallet.cppMigrateLegacyToDescriptorInspect captured patch +10 / −3
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index c5b0a496..987c2155 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -4366,6 +4366,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
for (const auto& path_to_remove : paths_to_remove) fs::remove(path_to_remove);
}
+ LogInfo("Loading new wallets after migration...\n");
// Migration successful, load all the migrated wallets.
for (std::shared_ptr<CWallet>* wallet_ptr : {&local_wallet, &res.watchonly_wallet, &res.solvables_wallet}) {
if (success && *wallet_ptr) {
@@ -4376,10 +4377,16 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
std::string wallet_name = wallet->GetName();
wallet.reset();
wallet = LoadWallet(context, wallet_name, /*load_on_start=*/std::nullopt, options, status, error, warnings);
- success = (wallet != nullptr);
+ if (!wallet) {
+ LogError("Failed to load wallet '%s' after migration. Rolling back migration to preserve consistency. "
+ "Error cause: %s\n", wallet_name, error.original);
+ success = false;
+ break;
+ }
- // When no wallet is set, set the main wallet.
- if (success && !res.wallet) {
+ // Set the first successfully loaded wallet as the main one.
+ // The loop order is intentional and must always start with the local wallet.
+ if (!res.wallet) {
res.wallet_name = wallet->GetName();
res.wallet = std::move(wallet);
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.