From 7a41c939f05f2208c33e8f09eecbbfd579fb4023 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Fri, 5 Jan 2024 18:42:06 -0500 Subject: [PATCH] wallet: Remove -format and bdb from wallet tool's createfromdump --- src/bitcoin-wallet.cpp | 1 - src/wallet/dump.cpp | 26 +++++++------------------- src/wallet/wallettool.cpp | 4 ---- test/functional/tool_wallet.py | 12 +----------- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index c37f9d29958..e578433065a 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -40,7 +40,6 @@ static void SetupWalletToolArgs(ArgsManager& argsman) argsman.AddArg("-debug=", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-descriptors", "Create descriptors wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-legacy", "Create legacy wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - argsman.AddArg("-format=", "The format of the wallet file to create. Either \"bdb\" or \"sqlite\". Only used with 'createfromdump'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-withinternalbdb", "Use the internal Berkeley DB parser when dumping a Berkeley DB wallet file (default: false)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); diff --git a/src/wallet/dump.cpp b/src/wallet/dump.cpp index c42ac068a3f..ceed5b6b52b 100644 --- a/src/wallet/dump.cpp +++ b/src/wallet/dump.cpp @@ -175,26 +175,14 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs:: dump_file.close(); return false; } - // Get the data file format with format_value as the default - std::string file_format = args.GetArg("-format", format_value); - if (file_format.empty()) { - error = _("No wallet file format provided. To use createfromdump, -format= must be provided."); + // Make sure that the dump was created from a sqlite database only as that is the only + // type of database that we still support. + // Other formats such as BDB should not be loaded into a sqlite database since they also + // use a different type of wallet entirely which is no longer compatible with this software. + if (format_value != "sqlite") { + error = strprintf(_("Error: Dumpfile specifies an unsupported database format (%s). Only sqlite database dumps are supported"), format_value); return false; } - DatabaseFormat data_format; - if (file_format == "bdb") { - data_format = DatabaseFormat::BERKELEY; - } else if (file_format == "sqlite") { - data_format = DatabaseFormat::SQLITE; - } else if (file_format == "bdb_swap") { - data_format = DatabaseFormat::BERKELEY_SWAP; - } else { - error = strprintf(_("Unknown wallet file format \"%s\" provided. Please provide one of \"bdb\" or \"sqlite\"."), file_format); - return false; - } - if (file_format != format_value) { - warnings.push_back(strprintf(_("Warning: Dumpfile wallet format \"%s\" does not match command line specified format \"%s\"."), format_value, file_format)); - } std::string format_hasher_line = strprintf("%s,%s\n", format_key, format_value); hasher << std::span{format_hasher_line}; @@ -202,7 +190,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs:: DatabaseStatus status; ReadDatabaseArgs(args, options); options.require_create = true; - options.require_format = data_format; + options.require_format = DatabaseFormat::SQLITE; std::unique_ptr database = MakeDatabase(wallet_path, options, status, error); if (!database) return false; diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index f7e7b74fc36..81a7c25196a 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -112,10 +112,6 @@ static void WalletShowInfo(CWallet* wallet_instance) bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) { - if (args.IsArgSet("-format") && command != "createfromdump") { - tfm::format(std::cerr, "The -format option can only be used with the \"createfromdump\" command.\n"); - return false; - } if (args.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") { tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n"); return false; diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py index 3488f35a1b2..552f31f68a4 100755 --- a/test/functional/tool_wallet.py +++ b/test/functional/tool_wallet.py @@ -145,21 +145,15 @@ class ToolWalletTest(BitcoinTestFramework): for k, v in e.items(): assert_equal(v, r[k]) - def do_tool_createfromdump(self, wallet_name, dumpfile, file_format=None): + def do_tool_createfromdump(self, wallet_name, dumpfile): dumppath = self.nodes[0].datadir_path / dumpfile rt_dumppath = self.nodes[0].datadir_path / "rt-{}.dump".format(wallet_name) - dump_data = self.read_dump(dumppath) - args = ["-wallet={}".format(wallet_name), "-dumpfile={}".format(dumppath)] - if file_format is not None: - args.append("-format={}".format(file_format)) args.append("createfromdump") load_output = "" - if file_format is not None and file_format != dump_data["format"]: - load_output += "Warning: Dumpfile wallet format \"{}\" does not match command line specified format \"{}\".\n".format(dump_data["format"], file_format) self.assert_tool_output(load_output, *args) assert (self.nodes[0].wallets_path / wallet_name).is_dir() @@ -316,7 +310,6 @@ class ToolWalletTest(BitcoinTestFramework): self.log.info('Checking createfromdump arguments') self.assert_raises_tool_error('No dump file provided. To use createfromdump, -dumpfile= must be provided.', '-wallet=todump', 'createfromdump') non_exist_dump = self.nodes[0].datadir_path / "wallet.nodump" - self.assert_raises_tool_error('Unknown wallet file format "notaformat" provided. Please provide one of "bdb" or "sqlite".', '-wallet=todump', '-format=notaformat', '-dumpfile={}'.format(wallet_dump), 'createfromdump') self.assert_raises_tool_error('Dump file {} does not exist.'.format(non_exist_dump), '-wallet=todump', '-dumpfile={}'.format(non_exist_dump), 'createfromdump') wallet_path = self.nodes[0].wallets_path / "todump2" self.assert_raises_tool_error('Failed to create database path \'{}\'. Database already exists.'.format(wallet_path), '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump') @@ -324,9 +317,6 @@ class ToolWalletTest(BitcoinTestFramework): self.log.info('Checking createfromdump') self.do_tool_createfromdump("load", "wallet.dump") - if self.is_bdb_compiled(): - self.do_tool_createfromdump("load-bdb", "wallet.dump", "bdb") - self.do_tool_createfromdump("load-sqlite", "wallet.dump", "sqlite") self.log.info('Checking createfromdump handling of magic and versions') bad_ver_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_ver1.dump"