mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge bitcoin/bitcoin#28976: wallet: Fix migration of blank wallets
c11c404281tests: Test migration of blank wallets (Andrew Chow)563b2a60d6wallet: Better error message when missing LegacySPKM during migration (Andrew Chow)b1d2c771d4wallet: Check for descriptors flag before migration (Andrew Chow)8c127ff1edwallet: Skip key and script migration for blank wallets (Andrew Chow) Pull request description: Blank wallets (wallets without any keys are scripts) are being detected as already being descriptor wallets even though they are not. This is because the check for whether a wallet is already a descriptor wallet uses the presence of a `LegacyScriptPubKeyMan` which is only setup when keys or scripts are found. This PR resolves this issue by checking for the descriptor wallet flag instead and subsequently skipping the keys and scripts part of migration for blank wallets. Fixes the issue mentioned in https://github.com/bitcoin/bitcoin/pull/28868#issuecomment-1809641110 ACKs for top commit: furszy: reACKc11c404281. CI failure is unrelated. ryanofsky: Code review ACKc11c404281Tree-SHA512: 2466fdf1542eb8489c841253191f85dc88365493f0bb3395b67dee3e43709a9993c68b9d7623657b54b779adbe68fc81962d60efef4802c5d461f154167af7f4
This commit is contained in:
@@ -3864,7 +3864,11 @@ std::optional<MigrationData> CWallet::GetDescriptorsForLegacy(bilingual_str& err
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan();
|
||||
assert(legacy_spkm);
|
||||
if (!Assume(legacy_spkm)) {
|
||||
// This shouldn't happen
|
||||
error = Untranslated(STR_INTERNAL_BUG("Error: Legacy wallet data missing"));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<MigrationData> res = legacy_spkm->MigrateToDescriptor();
|
||||
if (res == std::nullopt) {
|
||||
@@ -3879,8 +3883,9 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan();
|
||||
if (!legacy_spkm) {
|
||||
error = _("Error: This wallet is already a descriptor wallet");
|
||||
if (!Assume(legacy_spkm)) {
|
||||
// This shouldn't happen
|
||||
error = Untranslated(STR_INTERNAL_BUG("Error: Legacy wallet data missing"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4215,7 +4220,7 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
|
||||
}
|
||||
|
||||
// Before anything else, check if there is something to migrate.
|
||||
if (!local_wallet->GetLegacyScriptPubKeyMan()) {
|
||||
if (local_wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
|
||||
return util::Error{_("Error: This wallet is already a descriptor wallet")};
|
||||
}
|
||||
|
||||
@@ -4248,8 +4253,11 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& walle
|
||||
// First change to using SQLite
|
||||
if (!local_wallet->MigrateToSQLite(error)) return util::Error{error};
|
||||
|
||||
// Do the migration, and cleanup if it fails
|
||||
success = DoMigration(*local_wallet, context, error, res);
|
||||
// Do the migration of keys and scripts for non-blank wallets, and cleanup if it fails
|
||||
success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
|
||||
if (!success) {
|
||||
success = DoMigration(*local_wallet, context, error, res);
|
||||
}
|
||||
}
|
||||
|
||||
// In case of reloading failure, we need to remember the wallet dirs to remove
|
||||
|
||||
Reference in New Issue
Block a user