Skip to content

Commit 80e6ad9

Browse files
committed
Merge bitcoin/bitcoin#31250: wallet: Disable creating and loading legacy wallets
17bb63f wallet: Disallow loading legacy wallets (Ava Chow) 9f04e02 wallet: Disallow creating legacy wallets (Ava Chow) 6b24727 wallet: Disallow legacy wallet creation from the wallet tool (Ava Chow) 5e93b1f bench: Remove WalletLoadingLegacy benchmark (Ava Chow) 56f959d wallet: Remove wallettool salvage (Ava Chow) 7a41c93 wallet: Remove -format and bdb from wallet tool's createfromdump (Ava Chow) c847dee test: remove legacy wallet functional tests (Ava Chow) 20a9173 test: Remove legacy wallet tests from wallet_reindex.py (Ava Chow) 446d480 test: Remove legacy wallet tests from wallet_backwards_compatibility.py (Ava Chow) aff8029 test: wallet_signer.py bdb will be removed (Ava Chow) f94f939 test: Remove legacy wallet unit tests (Ava Chow) d9ac9db tests, gui: Use descriptors watchonly wallet for watchonly test (Ava Chow) Pull request description: To prepare for the deletion of legacy wallet code, disable creating or loading new legacy wallets. Tests for the legacy wallet specifically are deleted. Split from bitcoin/bitcoin#28710 ACKs for top commit: Sjors: re-ACK 17bb63f pablomartin4btc: re-ACK 17bb63f laanwj: re-ACK 17bb63f Tree-SHA512: d7a86df1f71f12451b335f22f7c3f0394166ac3f8f5b81f6bbf0321026e2e8ed621576656c371d70e202df1be4410b2b1c1acb5d5f0c341e7b67aaa0ac792e7c
2 parents 9719525 + 17bb63f commit 80e6ad9

File tree

115 files changed

+546
-5616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+546
-5616
lines changed

src/bench/wallet_ismine.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <addresstype.h>
66
#include <bench/bench.h>
7-
#include <bitcoin-build-config.h> // IWYU pragma: keep
87
#include <key.h>
98
#include <key_io.h>
109
#include <script/descriptor.h>
@@ -26,7 +25,7 @@
2625
#include <utility>
2726

2827
namespace wallet {
29-
static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_combo = 0)
28+
static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0)
3029
{
3130
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
3231

@@ -36,16 +35,13 @@ static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_co
3635

3736
// Setup the wallet
3837
// Loading the wallet will also create it
39-
uint64_t create_flags = 0;
40-
if (!legacy_wallet) {
41-
create_flags = WALLET_FLAG_DESCRIPTORS;
42-
}
38+
uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
4339
auto database = CreateMockableWalletDatabase();
4440
auto wallet = TestLoadWallet(std::move(database), context, create_flags);
4541

4642
// For a descriptor wallet, fill with num_combo combo descriptors with random keys
4743
// This benchmarks a non-HD wallet migrated to descriptors
48-
if (!legacy_wallet && num_combo > 0) {
44+
if (num_combo > 0) {
4945
LOCK(wallet->cs_wallet);
5046
for (int i = 0; i < num_combo; ++i) {
5147
CKey key;
@@ -70,13 +66,8 @@ static void WalletIsMine(benchmark::Bench& bench, bool legacy_wallet, int num_co
7066
TestUnloadWallet(std::move(wallet));
7167
}
7268

73-
#ifdef USE_BDB
74-
static void WalletIsMineLegacy(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/true); }
75-
BENCHMARK(WalletIsMineLegacy, benchmark::PriorityLevel::LOW);
76-
#endif
77-
78-
static void WalletIsMineDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/false); }
79-
static void WalletIsMineMigratedDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*legacy_wallet=*/false, /*num_combo=*/2000); }
69+
static void WalletIsMineDescriptors(benchmark::Bench& bench) { WalletIsMine(bench); }
70+
static void WalletIsMineMigratedDescriptors(benchmark::Bench& bench) { WalletIsMine(bench, /*num_combo=*/2000); }
8071
BENCHMARK(WalletIsMineDescriptors, benchmark::PriorityLevel::LOW);
8172
BENCHMARK(WalletIsMineMigratedDescriptors, benchmark::PriorityLevel::LOW);
8273
} // namespace wallet

src/bench/wallet_loading.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <addresstype.h>
66
#include <bench/bench.h>
7-
#include <bitcoin-build-config.h> // IWYU pragma: keep
87
#include <consensus/amount.h>
98
#include <outputtype.h>
109
#include <primitives/transaction.h>
@@ -32,7 +31,7 @@ static void AddTx(CWallet& wallet)
3231
wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
3332
}
3433

35-
static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
34+
static void WalletLoadingDescriptors(benchmark::Bench& bench)
3635
{
3736
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
3837

@@ -42,10 +41,7 @@ static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
4241

4342
// Setup the wallet
4443
// Loading the wallet will also create it
45-
uint64_t create_flags = 0;
46-
if (!legacy_wallet) {
47-
create_flags = WALLET_FLAG_DESCRIPTORS;
48-
}
44+
uint64_t create_flags = WALLET_FLAG_DESCRIPTORS;
4945
auto database = CreateMockableWalletDatabase();
5046
auto wallet = TestLoadWallet(std::move(database), context, create_flags);
5147

@@ -68,11 +64,5 @@ static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
6864
});
6965
}
7066

71-
#ifdef USE_BDB
72-
static void WalletLoadingLegacy(benchmark::Bench& bench) { WalletLoading(bench, /*legacy_wallet=*/true); }
73-
BENCHMARK(WalletLoadingLegacy, benchmark::PriorityLevel::HIGH);
74-
#endif
75-
76-
static void WalletLoadingDescriptors(benchmark::Bench& bench) { WalletLoading(bench, /*legacy_wallet=*/false); }
7767
BENCHMARK(WalletLoadingDescriptors, benchmark::PriorityLevel::HIGH);
7868
} // namespace wallet

src/bitcoin-wallet.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
4040
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
4141
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4242
argsman.AddArg("-legacy", "Create legacy wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
43-
argsman.AddArg("-format=<format>", "The format of the wallet file to create. Either \"bdb\" or \"sqlite\". Only used with 'createfromdump'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4443
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
4544
argsman.AddArg("-withinternalbdb", "Use the internal Berkeley DB parser when dumping a Berkeley DB wallet file (default: false)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
4645

4746
argsman.AddCommand("info", "Get wallet info");
4847
argsman.AddCommand("create", "Create new wallet file");
49-
argsman.AddCommand("salvage", "Attempt to recover private keys from a corrupt wallet. Warning: 'salvage' is experimental.");
5048
argsman.AddCommand("dump", "Print out all of the wallet key-value records");
5149
argsman.AddCommand("createfromdump", "Create new wallet file from dumped records");
5250
}

src/qt/test/wallettests.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -189,36 +189,28 @@ void SyncUpWallet(const std::shared_ptr<CWallet>& wallet, interfaces::Node& node
189189
QVERIFY(result.last_failed_block.IsNull());
190190
}
191191

192-
std::shared_ptr<CWallet> SetupLegacyWatchOnlyWallet(interfaces::Node& node, TestChain100Setup& test)
193-
{
194-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
195-
wallet->LoadWallet();
196-
{
197-
LOCK(wallet->cs_wallet);
198-
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
199-
wallet->SetupLegacyScriptPubKeyMan();
200-
// Add watched key
201-
CPubKey pubKey = test.coinbaseKey.GetPubKey();
202-
bool import_keys = wallet->ImportPubKeys({{pubKey.GetID(), false}}, {{pubKey.GetID(), pubKey}} , /*key_origins=*/{}, /*add_keypool=*/false, /*timestamp=*/1);
203-
assert(import_keys);
204-
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
205-
}
206-
SyncUpWallet(wallet, node);
207-
return wallet;
208-
}
209-
210-
std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test)
192+
std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test, bool watch_only = false)
211193
{
212194
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
213195
wallet->LoadWallet();
214196
LOCK(wallet->cs_wallet);
215197
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
216-
wallet->SetupDescriptorScriptPubKeyMans();
198+
if (watch_only) {
199+
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
200+
} else {
201+
wallet->SetupDescriptorScriptPubKeyMans();
202+
}
217203

218204
// Add the coinbase key
219205
FlatSigningProvider provider;
220206
std::string error;
221-
auto descs = Parse("combo(" + EncodeSecret(test.coinbaseKey) + ")", provider, error, /* require_checksum=*/ false);
207+
std::string key_str;
208+
if (watch_only) {
209+
key_str = HexStr(test.coinbaseKey.GetPubKey());
210+
} else {
211+
key_str = EncodeSecret(test.coinbaseKey);
212+
}
213+
auto descs = Parse("combo(" + key_str + ")", provider, error, /* require_checksum=*/ false);
222214
assert(!descs.empty());
223215
assert(descs.size() == 1);
224216
auto& desc = descs.at(0);
@@ -398,7 +390,7 @@ void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
398390

399391
void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
400392
{
401-
const std::shared_ptr<CWallet>& wallet = SetupLegacyWatchOnlyWallet(node, test);
393+
const std::shared_ptr<CWallet>& wallet = SetupDescriptorsWallet(node, test, /*watch_only=*/true);
402394

403395
// Create widgets and init models
404396
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
@@ -410,7 +402,7 @@ void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
410402
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
411403
walletModel.pollBalanceChanged();
412404
// Check balance in send dialog
413-
CompareBalance(walletModel, walletModel.wallet().getBalances().watch_only_balance,
405+
CompareBalance(walletModel, walletModel.wallet().getBalances().balance,
414406
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
415407

416408
// Set change address

src/wallet/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ target_link_libraries(bitcoin_wallet
4646
)
4747

4848
if(USE_BDB)
49-
target_sources(bitcoin_wallet PRIVATE bdb.cpp salvage.cpp)
49+
target_sources(bitcoin_wallet PRIVATE bdb.cpp)
5050
target_link_libraries(bitcoin_wallet PUBLIC BerkeleyDB::BerkeleyDB)
5151
endif()

src/wallet/db.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class WalletDatabase
182182
};
183183

184184
enum class DatabaseFormat {
185-
BERKELEY,
186185
SQLITE,
187186
BERKELEY_RO,
188187
BERKELEY_SWAP,

src/wallet/dump.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,34 +175,22 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
175175
dump_file.close();
176176
return false;
177177
}
178-
// Get the data file format with format_value as the default
179-
std::string file_format = args.GetArg("-format", format_value);
180-
if (file_format.empty()) {
181-
error = _("No wallet file format provided. To use createfromdump, -format=<format> must be provided.");
178+
// Make sure that the dump was created from a sqlite database only as that is the only
179+
// type of database that we still support.
180+
// Other formats such as BDB should not be loaded into a sqlite database since they also
181+
// use a different type of wallet entirely which is no longer compatible with this software.
182+
if (format_value != "sqlite") {
183+
error = strprintf(_("Error: Dumpfile specifies an unsupported database format (%s). Only sqlite database dumps are supported"), format_value);
182184
return false;
183185
}
184-
DatabaseFormat data_format;
185-
if (file_format == "bdb") {
186-
data_format = DatabaseFormat::BERKELEY;
187-
} else if (file_format == "sqlite") {
188-
data_format = DatabaseFormat::SQLITE;
189-
} else if (file_format == "bdb_swap") {
190-
data_format = DatabaseFormat::BERKELEY_SWAP;
191-
} else {
192-
error = strprintf(_("Unknown wallet file format \"%s\" provided. Please provide one of \"bdb\" or \"sqlite\"."), file_format);
193-
return false;
194-
}
195-
if (file_format != format_value) {
196-
warnings.push_back(strprintf(_("Warning: Dumpfile wallet format \"%s\" does not match command line specified format \"%s\"."), format_value, file_format));
197-
}
198186
std::string format_hasher_line = strprintf("%s,%s\n", format_key, format_value);
199187
hasher << std::span{format_hasher_line};
200188

201189
DatabaseOptions options;
202190
DatabaseStatus status;
203191
ReadDatabaseArgs(args, options);
204192
options.require_create = true;
205-
options.require_format = data_format;
193+
options.require_format = DatabaseFormat::SQLITE;
206194
std::unique_ptr<WalletDatabase> database = MakeDatabase(wallet_path, options, status, error);
207195
if (!database) return false;
208196

src/wallet/init.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
9898

9999
bool WalletInit::ParameterInteraction() const
100100
{
101-
#ifdef USE_BDB
102-
if (!BerkeleyDatabaseSanityCheck()) {
103-
return InitError(Untranslated("A version conflict was detected between the run-time BerkeleyDB library and the one used during compilation."));
104-
}
105-
#endif
106101
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
107102
for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
108103
LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);

src/wallet/rpc/wallet.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ static RPCHelpMan createwallet()
355355
{"blank", RPCArg::Type::BOOL, RPCArg::Default{false}, "Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed."},
356356
{"passphrase", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Encrypt the wallet with this passphrase."},
357357
{"avoid_reuse", RPCArg::Type::BOOL, RPCArg::Default{false}, "Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind."},
358-
{"descriptors", RPCArg::Type::BOOL, RPCArg::Default{true}, "Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation."
359-
" Setting to \"false\" will create a legacy wallet; This is only possible with the -deprecatedrpc=create_bdb setting because, the legacy wallet type is being deprecated and"
360-
" support for creating and opening legacy wallets will be removed in the future."},
358+
{"descriptors", RPCArg::Type::BOOL, RPCArg::Default{true}, "If set, must be \"true\""},
361359
{"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
362360
{"external_signer", RPCArg::Type::BOOL, RPCArg::Default{false}, "Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true."},
363361
},
@@ -402,13 +400,9 @@ static RPCHelpMan createwallet()
402400
if (!request.params[4].isNull() && request.params[4].get_bool()) {
403401
flags |= WALLET_FLAG_AVOID_REUSE;
404402
}
405-
if (self.Arg<bool>("descriptors")) {
406-
flags |= WALLET_FLAG_DESCRIPTORS;
407-
} else {
408-
if (!context.chain->rpcEnableDeprecated("create_bdb")) {
409-
throw JSONRPCError(RPC_WALLET_ERROR, "BDB wallet creation is deprecated and will be removed in a future release."
410-
" In this release it can be re-enabled temporarily with the -deprecatedrpc=create_bdb setting.");
411-
}
403+
flags |= WALLET_FLAG_DESCRIPTORS;
404+
if (!self.Arg<bool>("descriptors")) {
405+
throw JSONRPCError(RPC_WALLET_ERROR, "descriptors argument must be set to \"true\"; it is no longer possible to create a legacy wallet.");
412406
}
413407
if (!request.params[7].isNull() && request.params[7].get_bool()) {
414408
#ifdef ENABLE_EXTERNAL_SIGNER
@@ -418,12 +412,6 @@ static RPCHelpMan createwallet()
418412
#endif
419413
}
420414

421-
#ifndef USE_BDB
422-
if (!(flags & WALLET_FLAG_DESCRIPTORS)) {
423-
throw JSONRPCError(RPC_WALLET_ERROR, "Compiled without bdb support (required for legacy wallets)");
424-
}
425-
#endif
426-
427415
DatabaseOptions options;
428416
DatabaseStatus status;
429417
ReadDatabaseArgs(*context.args, options);

0 commit comments

Comments
 (0)