mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-08 02:41:07 +02:00
Merge bitcoin/bitcoin#26618: rpc: Prevent unloading a wallet when rescanning
109cbb819ddd20220a255791c40261f746260f42 doc: Add release notes for #26618 (Aurèle Oulès)
b13902d2e45ad1e73f79e221ffc16ce26b7c3ba5 rpc: Prevent unloading a wallet when rescanning (Aurèle Oulès)
Pull request description:
Fixes #26463.
This PR prevents a user from unloading a wallet if it is currently rescanning.
To test:
```bash
./src/bitcoin-cli -testnet -named createwallet wallet_name=wo disable_private_keys=true
./src/bitcoin-cli -testnet -rpcwallet=wo importdescriptors '[{
"desc": "addr(mmcuW74MyJUZuLnWXGQLoNXPrS9RbFz6gD)#tpnrahgc",
"timestamp": 0,
"active": false,
"internal": false,
"next": 0
}]'
./src/bitcoin-cli -testnet unloadwallet wo
error code: -4
error message:
Wallet is currently rescanning. Abort existing rescan or wait.
ACKs for top commit:
achow101:
ACK 109cbb819ddd20220a255791c40261f746260f42
w0xlt:
ACK 109cbb819d
kouloumos:
ACK 109cbb819ddd20220a255791c40261f746260f42
promag:
ACK 109cbb819ddd20220a255791c40261f746260f42
Tree-SHA512: 15fdddf4cf9f3fa08f52069fe4a25a76e04a55bb2586b031bfb0393dce7f175dcdb52823e132a7dff6a894539beeb980a1aad2a792790be036be6977628149b2
This commit is contained in:
commit
1aedc3b6c8
4
doc/release-notes-26618.md
Normal file
4
doc/release-notes-26618.md
Normal file
@ -0,0 +1,4 @@
|
||||
RPC Wallet
|
||||
----------
|
||||
|
||||
- RPC `unloadwallet` now fails if a rescan is in progress. (#26618)
|
@ -445,13 +445,20 @@ static RPCHelpMan unloadwallet()
|
||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
|
||||
}
|
||||
|
||||
// Release the "main" shared pointer and prevent further notifications.
|
||||
// Note that any attempt to load the same wallet would fail until the wallet
|
||||
// is destroyed (see CheckUniqueFileid).
|
||||
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());
|
||||
if (!RemoveWallet(context, wallet, load_on_start, warnings)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded");
|
||||
{
|
||||
WalletRescanReserver reserver(*wallet);
|
||||
if (!reserver.reserve()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
|
||||
}
|
||||
|
||||
// Release the "main" shared pointer and prevent further notifications.
|
||||
// Note that any attempt to load the same wallet would fail until the wallet
|
||||
// is destroyed (see CheckUniqueFileid).
|
||||
std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
|
||||
if (!RemoveWallet(context, wallet, load_on_start, warnings)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded");
|
||||
}
|
||||
}
|
||||
|
||||
UnloadWallet(std::move(wallet));
|
||||
|
Loading…
x
Reference in New Issue
Block a user