wallet: init, don't error out when loading legacy wallets

Instead of failing during initialization when encountering a legacy wallet, skip
loading the wallet and notify the user accordingly.

This allows users to access migration functionalities without needing to manually
remove the wallet from settings.json or resort to using the bitcoin-wallet utility.

This means that GUI users will be able to use the migration button, and bitcoin-cli
users will be able to call the migratewallet RPC directly after init.
This commit is contained in:
furszy
2025-05-08 11:54:47 -04:00
parent 66c968b4b4
commit 9f94de5bb5
5 changed files with 16 additions and 5 deletions

View File

@@ -184,6 +184,7 @@ enum class DatabaseStatus {
SUCCESS, SUCCESS,
FAILED_BAD_PATH, FAILED_BAD_PATH,
FAILED_BAD_FORMAT, FAILED_BAD_FORMAT,
FAILED_LEGACY_DISABLED,
FAILED_ALREADY_LOADED, FAILED_ALREADY_LOADED,
FAILED_ALREADY_EXISTS, FAILED_ALREADY_EXISTS,
FAILED_NOT_FOUND, FAILED_NOT_FOUND,

View File

@@ -99,6 +99,10 @@ bool VerifyWallets(WalletContext& context)
if (!MakeWalletDatabase(wallet_file, options, status, error_string)) { if (!MakeWalletDatabase(wallet_file, options, status, error_string)) {
if (status == DatabaseStatus::FAILED_NOT_FOUND) { if (status == DatabaseStatus::FAILED_NOT_FOUND) {
chain.initWarning(Untranslated(strprintf("Skipping -wallet path that doesn't exist. %s", error_string.original))); chain.initWarning(Untranslated(strprintf("Skipping -wallet path that doesn't exist. %s", error_string.original)));
} else if (status == DatabaseStatus::FAILED_LEGACY_DISABLED) {
// Skipping legacy wallets as they will not be loaded.
// This will be properly communicated to the user during the loading process.
continue;
} else { } else {
chain.initError(error_string); chain.initError(error_string);
return false; return false;
@@ -132,8 +136,13 @@ bool LoadWallets(WalletContext& context)
bilingual_str error; bilingual_str error;
std::vector<bilingual_str> warnings; std::vector<bilingual_str> warnings;
std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error); std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error);
if (!database && status == DatabaseStatus::FAILED_NOT_FOUND) { if (!database) {
continue; if (status == DatabaseStatus::FAILED_NOT_FOUND) continue;
if (status == DatabaseStatus::FAILED_LEGACY_DISABLED) {
// Inform user that legacy wallet is not loaded and suggest upgrade options
chain.initWarning(error);
continue;
}
} }
chain.initMessage(_("Loading wallet…")); chain.initMessage(_("Loading wallet…"));
std::shared_ptr<CWallet> pwallet = database ? CWallet::Create(context, name, std::move(database), options.create_flags, error, warnings) : nullptr; std::shared_ptr<CWallet> pwallet = database ? CWallet::Create(context, name, std::move(database), options.create_flags, error, warnings) : nullptr;

View File

@@ -123,6 +123,7 @@ void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& st
switch (status) { switch (status) {
case DatabaseStatus::FAILED_NOT_FOUND: case DatabaseStatus::FAILED_NOT_FOUND:
case DatabaseStatus::FAILED_BAD_FORMAT: case DatabaseStatus::FAILED_BAD_FORMAT:
case DatabaseStatus::FAILED_LEGACY_DISABLED:
code = RPC_WALLET_NOT_FOUND; code = RPC_WALLET_NOT_FOUND;
break; break;
case DatabaseStatus::FAILED_ALREADY_LOADED: case DatabaseStatus::FAILED_ALREADY_LOADED:

View File

@@ -1383,8 +1383,8 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
// BERKELEY_RO can only be opened if require_format was set, which only occurs in migration. // BERKELEY_RO can only be opened if require_format was set, which only occurs in migration.
if (format && format == DatabaseFormat::BERKELEY_RO && (!options.require_format || options.require_format != DatabaseFormat::BERKELEY_RO)) { if (format && format == DatabaseFormat::BERKELEY_RO && (!options.require_format || options.require_format != DatabaseFormat::BERKELEY_RO)) {
error = Untranslated(strprintf("Failed to open database path '%s'. The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC).", fs::PathToString(path))); error = Untranslated(strprintf("Failed to open database path '%s'. The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC or the GUI option).", fs::PathToString(path)));
status = DatabaseStatus::FAILED_BAD_FORMAT; status = DatabaseStatus::FAILED_LEGACY_DISABLED;
return nullptr; return nullptr;
} }

View File

@@ -378,7 +378,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
# Restore the wallet to master # Restore the wallet to master
# Legacy wallets are no longer supported. Trying to load these should result in an error # Legacy wallets are no longer supported. Trying to load these should result in an error
assert_raises_rpc_error(-18, "The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC)", node_master.restorewallet, wallet_name, backup_path) assert_raises_rpc_error(-18, "The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC or the GUI option)", node_master.restorewallet, wallet_name, backup_path)
self.test_v22_inactivehdchain_path() self.test_v22_inactivehdchain_path()