Merge bitcoin/bitcoin#32984: wallet: Set migrated wallet name only on success

060695c22a test: Failed load after migrate should restore backup (MarcoFalke)
8a4cfddf23 wallet: Set migrated wallet name only on success (Ava Chow)

Pull request description:

  After a wallet is migrated and we are trying to load it, if it could not be loaded, don't try to set the wallet name. Otherwise we have a segfault.

  This can be tested by migrated a legacy wallet from another network (e.g. trying to migrate a testnet wallet on mainnet). The fixed behavior is return an error and restore the backup.

ACKs for top commit:
  davidgumberg:
    ACK 060695c22a
  furszy:
    ACK 060695c22a
  rkrux:
    ACK 060695c22a
  w0xlt:
    reACK 060695c22a
  pablomartin4btc:
    ACK 060695c22a

Tree-SHA512: f4289e0b3dedef0a3d734c18604f2fd0df0dc65e9641bc342cfa45088d2540a3f6631bbea8bdd394b2631fa83b38e8ac37c83cfc4b53b19dcbd0b820a9beb6e4
This commit is contained in:
merge-script
2025-07-24 12:00:52 +01:00
2 changed files with 30 additions and 5 deletions

View File

@@ -4306,7 +4306,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
success = (wallet != nullptr);
// When no wallet is set, set the main wallet.
if (!res.wallet) {
if (success && !res.wallet) {
res.wallet_name = wallet->GetName();
res.wallet = std::move(wallet);
}