mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-29 11:12:10 +01:00
Merge bitcoin/bitcoin#26192: rpc: Improve error when wallet is already loaded
04609284ad5e0b72651f2d4b43263461ada40816 rpc: Improve error when wallet is already loaded (Aurèle Oulès) Pull request description: Currently, trying to load a descriptor (sqlite) wallet that is already loaded throws the following error: > error code: -4 > error message: > Wallet file verification failed. SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of Bitcoin Core? I don't think it is very clear what it means for a user. While a legacy wallet would throw: > error code: -35 > error message: > Wallet file verification failed. Refusing to load database. Data file '/home/user/.bitcoin/signet/wallets/test_wallet/wallet.dat' is already loaded. This PR changes the error message for both types of wallet to: > error code: -35 > error message: > Wallet file verification failed. Wallet "test_wallet" is already loaded. ACKs for top commit: achow101: ACK 04609284ad5e0b72651f2d4b43263461ada40816 hernanmarino: ACK 0460928 theStack: Tested ACK 04609284ad5e0b72651f2d4b43263461ada40816 Tree-SHA512: a8f3d5133bfaef7417a6c05d160910ea08f32ac62bfdf7f5ec305ff5b62e9113b55f385abab4d5a4ad711aabcb1eb7ef746eb41f841b196e8fb5393ab3ccc01e
This commit is contained in:
commit
cb552c5f21
@ -226,6 +226,14 @@ static RPCHelpMan loadwallet()
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
|
||||
|
||||
{
|
||||
LOCK(context.wallets_mutex);
|
||||
if (std::any_of(context.wallets.begin(), context.wallets.end(), [&name](const auto& wallet) { return wallet->GetName() == name; })) {
|
||||
throw JSONRPCError(RPC_WALLET_ALREADY_LOADED, "Wallet \"" + name + "\" is already loaded.");
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(context, name, load_on_start, options, status, error, warnings);
|
||||
|
||||
HandleWalletError(wallet, status, error);
|
||||
|
@ -303,12 +303,8 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path), self.nodes[0].loadwallet, 'wallets')
|
||||
|
||||
# Fail to load duplicate wallets
|
||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", "wallet.dat")
|
||||
if self.options.descriptors:
|
||||
assert_raises_rpc_error(-4, f"Wallet file verification failed. SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of {self.config['environment']['PACKAGE_NAME']}?", self.nodes[0].loadwallet, wallet_names[0])
|
||||
else:
|
||||
assert_raises_rpc_error(-35, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, wallet_names[0])
|
||||
|
||||
assert_raises_rpc_error(-35, "Wallet \"w1\" is already loaded.", self.nodes[0].loadwallet, wallet_names[0])
|
||||
if not self.options.descriptors:
|
||||
# This tests the default wallet that BDB makes, so SQLite wallet doesn't need to test this
|
||||
# Fail to load duplicate wallets by different ways (directory and filepath)
|
||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat")
|
||||
|
Loading…
x
Reference in New Issue
Block a user