From 55ce8cec4325a9e44fda5de73ebcce2e3cae5457 Mon Sep 17 00:00:00 2001 From: Enrico Rubboli Date: Fri, 28 Aug 2026 11:17:47 +0200 Subject: [PATCH] Perform the rescan when adding a standalone address `address_add_standalone_watch_only`, `address_add_standalone_private_key` and `address_add_standalone_multisig` reset the wallet to genesis but never synced it back, leaving the actual rescan to the controller's background sync loop. In wallet-cli non-interactive mode (`--commands-file`) the process exits as soon as the commands are exhausted, which closes the wallet service command channel; the worker's `biased` select then cancels the in-flight sync before it makes any progress. The result is that the rescan never happens and the wallet is left at genesis, so every subsequent wallet open has to rescan the whole blockchain. If the sync did manage to issue a node RPC call before the teardown, the cancelled call was also reported as a confusing "Unexpected RPC error: Response error: Custom error: Error reason could not be found" (jsonrpsee's placeholder for a client whose background connection task is gone without a recorded disconnect reason). Sync right after the reset, as `wallet_rescan` already does, so the rescan is complete by the time the command returns. Also skip the reset entirely when adding the address failed, so a failed command no longer discards the wallet's scan state. --- CHANGELOG.md | 8 ++++++++ wallet/wallet-rpc-lib/src/rpc/mod.rs | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d69fd82c0..ef62f43ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/ ## [Unreleased] +### Fixed + - Wallet: + - Fixed an issue where `standalone-add-watch-only-address`, `standalone-add-private-key-from-hex` and + `standalone-add-multisig` (and the corresponding RPC methods) would reset the wallet to genesis but never + perform the announced rescan; the rescan is now done before the command returns. Previously, in `wallet-cli` + non-interactive mode the process would exit before the background rescan could run, leaving the wallet + stuck at genesis so that every subsequent wallet open had to rescan the whole blockchain. + ## [1.4.0] - 2026-07-09 ### Added diff --git a/wallet/wallet-rpc-lib/src/rpc/mod.rs b/wallet/wallet-rpc-lib/src/rpc/mod.rs index 3f28c91f2..6b333abb7 100644 --- a/wallet/wallet-rpc-lib/src/rpc/mod.rs +++ b/wallet/wallet-rpc-lib/src/rpc/mod.rs @@ -366,8 +366,9 @@ where .await? .add_standalone_address(pkh, label); - if !no_rescan { + if res.is_ok() && !no_rescan { w.reset_wallet_to_genesis()?; + w.sync_once().await?; } res @@ -396,8 +397,9 @@ where .await? .add_standalone_private_key(private_key, label); - if !no_rescan { + if res.is_ok() && !no_rescan { w.reset_wallet_to_genesis()?; + w.sync_once().await?; } res @@ -455,8 +457,9 @@ where .await? .add_standalone_multisig(challenge, label); - if !no_rescan { + if res.is_ok() && !no_rescan { w.reset_wallet_to_genesis()?; + w.sync_once().await?; } res