Skip to content

Commit b933813

Browse files
committed
Merge bitcoin/bitcoin#32619: wallet, rpc, gui: List legacy wallets with a message about migration
f3a444c gui: Disallow loading legacy wallets (Ava Chow) 0995517 wallet, rpc: Give warning in listwalletdir for legacy wallets (Ava Chow) Pull request description: A new field `warnings` is added for each wallet in `listwalletdir`. If a legacy wallet is detected, the warning will contain a message that the wallet is a legacy wallet and will need to be migrated before it can be loaded. In the GUI, the "Open Wallet" menu is changed to show legacy wallets greyed out with "(needs migration)" appended to their name to indicate to the user that the legacy wallet will need to be migrated. ACKs for top commit: maflcko: lgtm ACK f3a444c adyshimony: Test ACK [f3a444c](bitcoin/bitcoin@f3a444c) furszy: Code review ACK f3a444c w0xlt: Code Review ACK bitcoin/bitcoin@f3a444c Tree-SHA512: 496caec0ca37845487bd709e592240315eb23461fbd697e68a7fde8e4d9b74b48aab1212c88dbbcc8a107a896b824c2e1f69691068641812ae903f873fa2f22b
2 parents 053bda5 + f3a444c commit b933813

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/qt/bitcoingui.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,19 @@ void BitcoinGUI::createActions()
398398
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
399399
m_open_wallet_menu->clear();
400400
for (const auto& [path, info] : m_wallet_controller->listWalletDir()) {
401-
const auto& [loaded, _] = info;
401+
const auto& [loaded, format] = info;
402402
QString name = GUIUtil::WalletDisplayName(path);
403403
// An single ampersand in the menu item's text sets a shortcut for this item.
404404
// Single & are shown when && is in the string. So replace & with &&.
405405
name.replace(QChar('&'), QString("&&"));
406+
bool is_legacy = format == "bdb";
407+
if (is_legacy) {
408+
name += " (needs migration)";
409+
}
406410
QAction* action = m_open_wallet_menu->addAction(name);
407411

408-
if (loaded) {
409-
// This wallet is already loaded
412+
if (loaded || is_legacy) {
413+
// This wallet is already loaded or it is a legacy wallet
410414
action->setEnabled(false);
411415
continue;
412416
}

src/wallet/rpc/wallet.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ static RPCHelpMan listwalletdir()
135135
{RPCResult::Type::OBJ, "", "",
136136
{
137137
{RPCResult::Type::STR, "name", "The wallet name"},
138+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
139+
{
140+
{RPCResult::Type::STR, "", ""},
141+
}},
138142
}},
139143
}},
140144
}
@@ -146,9 +150,14 @@ static RPCHelpMan listwalletdir()
146150
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
147151
{
148152
UniValue wallets(UniValue::VARR);
149-
for (const auto& [path, _] : ListDatabases(GetWalletDir())) {
153+
for (const auto& [path, db_type] : ListDatabases(GetWalletDir())) {
150154
UniValue wallet(UniValue::VOBJ);
151155
wallet.pushKV("name", path.utf8string());
156+
UniValue warnings(UniValue::VARR);
157+
if (db_type == "bdb") {
158+
warnings.push_back("This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded");
159+
}
160+
wallet.pushKV("warnings", warnings);
152161
wallets.push_back(std::move(wallet));
153162
}
154163

test/functional/wallet_migration.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def migrate_and_get_rpc(self, wallet_name, **kwargs):
113113
shutil.copyfile(self.old_node.wallets_path / "wallet.dat", self.master_node.wallets_path / "wallet.dat")
114114
else:
115115
shutil.copytree(self.old_node.wallets_path / wallet_name, self.master_node.wallets_path / wallet_name)
116+
# Check that the wallet shows up in listwalletdir with a warning about migration
117+
wallets = self.master_node.listwalletdir()
118+
for w in wallets["wallets"]:
119+
if w["name"] == wallet_name:
120+
assert_equal(w["warnings"], ["This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded"])
116121
# Migrate, checking that rescan does not occur
117122
with self.master_node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Rescanning"]):
118123
migrate_info = self.master_node.migratewallet(wallet_name=wallet_name, **kwargs)
@@ -548,7 +553,7 @@ def test_default_wallet(self):
548553
assert_equal(info["format"], "sqlite")
549554

550555
walletdir_list = wallet.listwalletdir()
551-
assert {"name": info["walletname"]} in walletdir_list["wallets"]
556+
assert {"name": info["walletname"]} in [{"name": w["name"]} for w in walletdir_list["wallets"]]
552557

553558
# Check backup existence and its non-empty wallet filename
554559
backup_filename = f"default_wallet_{curr_time}.legacy.bak"

test/functional/wallet_multiwallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def wallet_file(name):
7272
return wallet_dir(name, "wallet.dat")
7373
return wallet_dir(name)
7474

75-
assert_equal(self.nodes[0].listwalletdir(), {'wallets': [{'name': self.default_wallet_name}]})
75+
assert_equal(self.nodes[0].listwalletdir(), {'wallets': [{'name': self.default_wallet_name, "warnings": []}]})
7676

7777
# check wallet.dat is created
7878
self.stop_nodes()

0 commit comments

Comments
 (0)