642 | @@ -643,6 +643,10 @@ class WalletLoaderImpl : public WalletLoader
643 | DatabaseStatus status;
644 | bilingual_str error;
645 | auto db = MakeWalletDatabase(wallet_name, options, status, error);
646 | + if (!db && status == wallet::DatabaseStatus::FAILED_LEGACY_DISABLED) {
647 | + options.require_format = wallet::DatabaseFormat::BERKELEY_RO;
648 | + db = MakeWalletDatabase(wallet_name, options, status, error);
649 | + }
While adding this BERKELEY_RO database format fallback in this seemingly generic isEncrypted function looks unsafe, it is fine because the only usage of this function lies in the wallet migration functionality in the GUI. The FAILED_LEGACY_DISABLED error from MakeDatabase also enforces the flow towards wallet migration.
Using the require_format = DatabaseFormat::BERKELEY_RO checks seems like an indirect way of validating the migration flow though when the MakeWalletDatabase function already decides to pick BERKELEY_RO format for BDB wallet files, perhaps a boolean might replace it in the future.
Even if this was not limited to migration, this would still be correct because we need to be able to open legacy wallets in order to determine whether the wallet is encrypted. The database is closed once this function exits. The only reason to do this is because MakeWalletDatabase needs to be explicitly told when to use BERKELEY_RO so that we don't accidentally try to use legacy wallets in normal operation.