Skip to content

Commit 1bee1e6

Browse files
committed
Do not create default wallet
No longer create a default wallet. The default wallet will still be loaded if it exists and not other wallets were specified (anywhere, including settings.json, bitcoin.conf, and command line). Tests are updated to be started with -wallet= if they need the default wallet. Added test to wallet_startup.py testing that no default wallet is created and that it is loaded if it exists and no other wallets were specified.
1 parent 78cb45d commit 1bee1e6

18 files changed

+67
-43
lines changed

doc/release-notes-15454.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Wallet
2+
------
3+
4+
Bitcoin Core will no longer create an unnamed `""` wallet by default when no wallet is specified on the command line or in the configuration files.
5+
For backwards compatibility, if an unnamed `""` wallet already exists and would have been loaded previously, then it will still be loaded.
6+
Users without an unnamed `""` wallet and without any other wallets to be loaded on startup will be prompted to either choose a wallet to load, or to create a new wallet.

src/interfaces/wallet.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,7 @@ class WalletImpl : public Wallet
488488
class WalletClientImpl : public WalletClient
489489
{
490490
public:
491-
WalletClientImpl(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
492-
: m_wallet_filenames(std::move(wallet_filenames))
491+
WalletClientImpl(Chain& chain, ArgsManager& args)
493492
{
494493
m_context.chain = &chain;
495494
m_context.args = &args;
@@ -506,8 +505,8 @@ class WalletClientImpl : public WalletClient
506505
m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
507506
}
508507
}
509-
bool verify() override { return VerifyWallets(*m_context.chain, m_wallet_filenames); }
510-
bool load() override { return LoadWallets(*m_context.chain, m_wallet_filenames); }
508+
bool verify() override { return VerifyWallets(*m_context.chain); }
509+
bool load() override { return LoadWallets(*m_context.chain); }
511510
void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
512511
void flush() override { return FlushWallets(); }
513512
void stop() override { return StopWallets(); }
@@ -566,9 +565,9 @@ class WalletClientImpl : public WalletClient
566565

567566
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
568567

569-
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
568+
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args)
570569
{
571-
return MakeUnique<WalletClientImpl>(chain, args, std::move(wallet_filenames));
570+
return MakeUnique<WalletClientImpl>(chain, args);
572571
}
573572

574573
} // namespace interfaces

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet);
411411

412412
//! Return implementation of ChainClient interface for a wallet client. This
413413
//! function will be undefined in builds where ENABLE_WALLET is false.
414-
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames);
414+
std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args);
415415

416416
} // namespace interfaces
417417

src/wallet/init.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,7 @@ void WalletInit::Construct(NodeContext& node) const
107107
LogPrintf("Wallet disabled!\n");
108108
return;
109109
}
110-
// If there's no -wallet setting with a list of wallets to load, set it to
111-
// load the default "" wallet.
112-
if (!args.IsArgSet("wallet")) {
113-
args.LockSettings([&](util::Settings& settings) {
114-
util::SettingsValue wallets(util::SettingsValue::VARR);
115-
wallets.push_back(""); // Default wallet name is ""
116-
settings.rw_settings["wallet"] = wallets;
117-
});
118-
}
119-
auto wallet_client = interfaces::MakeWalletClient(*node.chain, args, args.GetArgs("-wallet"));
110+
auto wallet_client = interfaces::MakeWalletClient(*node.chain, args);
120111
node.wallet_client = wallet_client.get();
121112
node.chain_clients.emplace_back(std::move(wallet_client));
122113
}

src/wallet/load.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <univalue.h>
1818

19-
bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
19+
bool VerifyWallets(interfaces::Chain& chain)
2020
{
2121
if (gArgs.IsArgSet("-walletdir")) {
2222
fs::path wallet_dir = gArgs.GetArg("-walletdir", "");
@@ -41,10 +41,27 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
4141

4242
chain.initMessage(_("Verifying wallet(s)...").translated);
4343

44+
// For backwards compatibility if an unnamed top level wallet exists in the
45+
// wallets directory, include it in the default list of wallets to load.
46+
if (!gArgs.IsArgSet("wallet")) {
47+
DatabaseOptions options;
48+
DatabaseStatus status;
49+
bilingual_str error_string;
50+
options.require_existing = true;
51+
options.verify = false;
52+
if (MakeWalletDatabase("", options, status, error_string)) {
53+
gArgs.LockSettings([&](util::Settings& settings) {
54+
util::SettingsValue wallets(util::SettingsValue::VARR);
55+
wallets.push_back(""); // Default wallet name is ""
56+
settings.rw_settings["wallet"] = wallets;
57+
});
58+
}
59+
}
60+
4461
// Keep track of each wallet absolute path to detect duplicates.
4562
std::set<fs::path> wallet_paths;
4663

47-
for (const auto& wallet_file : wallet_files) {
64+
for (const auto& wallet_file : gArgs.GetArgs("-wallet")) {
4865
const fs::path path = fs::absolute(wallet_file, GetWalletDir());
4966

5067
if (!wallet_paths.insert(path).second) {
@@ -65,10 +82,10 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
6582
return true;
6683
}
6784

68-
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
85+
bool LoadWallets(interfaces::Chain& chain)
6986
{
7087
try {
71-
for (const std::string& name : wallet_files) {
88+
for (const std::string& name : gArgs.GetArgs("-wallet")) {
7289
DatabaseOptions options;
7390
DatabaseStatus status;
7491
options.verify = false; // No need to verify, assuming verified earlier in VerifyWallets()

src/wallet/load.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class Chain;
1717
} // namespace interfaces
1818

1919
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
20-
bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files);
20+
bool VerifyWallets(interfaces::Chain& chain);
2121

2222
//! Load wallet databases.
23-
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files);
23+
bool LoadWallets(interfaces::Chain& chain);
2424

2525
//! Complete startup of wallets.
2626
void StartWallets(CScheduler& scheduler, const ArgsManager& args);

src/wallet/test/init_test_fixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
1212
{
13-
m_wallet_client = MakeWalletClient(*m_chain, *Assert(m_node.args), {});
13+
m_wallet_client = MakeWalletClient(*m_chain, *Assert(m_node.args));
1414

1515
std::string sep;
1616
sep += fs::path::preferred_separator;

src/wallet/test/wallet_test_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct WalletTestingSetup : public TestingSetup {
2121
explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
2222

2323
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node);
24-
std::unique_ptr<interfaces::WalletClient> m_wallet_client = interfaces::MakeWalletClient(*m_chain, *Assert(m_node.args), {});
24+
std::unique_ptr<interfaces::WalletClient> m_wallet_client = interfaces::MakeWalletClient(*m_chain, *Assert(m_node.args));
2525
CWallet m_wallet;
2626
std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
2727
};

test/functional/feature_backwards_compatibility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def set_test_params(self):
3636
self.num_nodes = 6
3737
# Add new version after each release:
3838
self.extra_args = [
39-
["-addresstype=bech32"], # Pre-release: use to mine blocks
39+
["-addresstype=bech32", "-wallet="], # Pre-release: use to mine blocks
4040
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # Pre-release: use to receive coins, swap wallets, etc
4141
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.19.1
4242
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.18.1
4343
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.17.2
44-
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.16.3
44+
["-nowallet", "-walletrbf=1", "-addresstype=bech32", "-wallet=wallet.dat"], # v0.16.3
4545
]
4646

4747
def skip_test_if_missing_module(self):

test/functional/feature_fee_estimation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def set_test_params(self):
145145
# mine non-standard txs (e.g. txs with "dust" outputs)
146146
# Force fSendTrickle to true (via whitelist.noban)
147147
self.extra_args = [
148-
["-acceptnonstdtxn", "[email protected]"],
149-
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=68000"],
150-
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=32000"],
148+
["-acceptnonstdtxn", "[email protected]", "-wallet="],
149+
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=68000", "-wallet="],
150+
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=32000", "-wallet="],
151151
]
152152

153153
def skip_test_if_missing_module(self):

0 commit comments

Comments
 (0)