From b13902d2e45ad1e73f79e221ffc16ce26b7c3ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A8le=20Oul=C3=A8s?= Date: Thu, 8 Dec 2022 16:45:21 +0100 Subject: [PATCH 1/2] rpc: Prevent unloading a wallet when rescanning --- src/wallet/rpc/wallet.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 971814e9cda..88bf5e3106d 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -437,13 +437,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 warnings; - std::optional load_on_start = request.params[1].isNull() ? std::nullopt : std::optional(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 load_on_start = request.params[1].isNull() ? std::nullopt : std::optional(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)); From 109cbb819ddd20220a255791c40261f746260f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A8le=20Oul=C3=A8s?= Date: Thu, 8 Dec 2022 16:45:35 +0100 Subject: [PATCH 2/2] doc: Add release notes for #26618 --- doc/release-notes-26618.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 doc/release-notes-26618.md diff --git a/doc/release-notes-26618.md b/doc/release-notes-26618.md new file mode 100644 index 00000000000..9d1ef3bd2ee --- /dev/null +++ b/doc/release-notes-26618.md @@ -0,0 +1,4 @@ +RPC Wallet +---------- + +- RPC `unloadwallet` now fails if a rescan is in progress. (#26618)