Perform the rescan when adding a standalone address - #2107
Open
erubboli wants to merge 1 commit into
Open
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Adding a standalone address with a rescan (
standalone-add-watch-only-address,standalone-add-private-key-from-hex,standalone-add-multisig, and the correspondingaddress_add_standalone_*RPC methods) callsreset_wallet_to_genesis()and nothing else. The actual rescan is left to the controller's background sync loop.In
wallet-clinon-interactive mode (--commands-file) the process exits as soon as the commands file is exhausted. That closes the wallet service command channel, and the worker'sbiasedselect cancels the in-flight sync before it makes any progress. So:The rescan never runs and the wallet is left at genesis. Every subsequent
wallet-openthen has to rescan the whole blockchain (on mainnet that is ~673k blocks, which is slow enough that users interrupt it and leave a stale SQLite journal behind).The teardown can surface a confusing error. If the sync did issue a node RPC call before the process tore down, the cancelled call is logged as:
That string is jsonrpsee's placeholder for "the client's background connection task is gone and no disconnect reason was recorded" — i.e. the RPC client was dropped mid-request. Nothing is wrong on the node side, which is why the node logs are silent.
Reported for
standalone-add-multisigon mainnet (v1.4.0, aarch64), but it affects all three commands. Cold mode is unaffected because no sync is attempted there.Fix
Sync right after the reset, the same way
wallet_rescanalready does, so the rescan is complete by the time the command returns and the printed "Rescanning the blockchain to detect balance in added new addresses" is true.Also skip the reset when the add itself failed, so e.g. a duplicate-address error no longer discards the wallet's scan state and forces a full rescan later.
Notes
wallet-rescanalready behaves this way, and--no-rescan trueremains available for callers that do not want to wait. Note that over a remote wallet RPC daemon a long rescan can exceed the client's default 60s request timeout — that is pre-existing forwallet_rescanand is not addressed here.Testing
Reproduced on a local regtest chain (500 blocks): before the change the wallet is left at height 0 after
standalone-add-multisigand the next open rescans the entire chain; after the change the rescan runs inline and the next open needs no sync at all. A failed (duplicate) add no longer resets the wallet.Existing tests pass:
cargo test -p wallet-rpc-lib, and the functional testswallet_multisig_address.py,wallet_watch_address.py,wallet_list_utxos.py,wallet_htlc_spend.py,wallet_htlc_refund_multisig.py,wallet_tokens_transfer_from_multisig_addr.py.