Skip to content

Perform the rescan when adding a standalone address - #2107

Open
erubboli wants to merge 1 commit into
mintlayer:masterfrom
erubboli:fix/standalone-add-rescan-not-performed
Open

Perform the rescan when adding a standalone address#2107
erubboli wants to merge 1 commit into
mintlayer:masterfrom
erubboli:fix/standalone-add-rescan-not-performed

Conversation

@erubboli

Copy link
Copy Markdown
Member

Problem

Adding a standalone address with a rescan (standalone-add-watch-only-address, standalone-add-private-key-from-hex, standalone-add-multisig, and the corresponding address_add_standalone_* RPC methods) calls reset_wallet_to_genesis() and nothing else. The actual rescan is left to the controller's background sync loop.

In wallet-cli non-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's biased select 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-open then 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:

    ERROR wallet_controller: Wallet sync error: Wallet sync error: Unexpected RPC error:
    Response error: Custom error: Error reason could not be found.
    This is a bug. Please open an issue.
    

    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-multisig on 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_rescan already 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

  • The command now blocks for the duration of the rescan. wallet-rescan already behaves this way, and --no-rescan true remains 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 for wallet_rescan and is not addressed here.
  • A better long-term fix is to not reset the wallet to genesis at all and scan for the newly added destination without moving the wallet's best block, so that an interrupted rescan costs nothing. Filed separately as Wallet: scan for a newly added standalone address without resetting the wallet to genesis #2106.

Testing

Reproduced on a local regtest chain (500 blocks): before the change the wallet is left at height 0 after standalone-add-multisig and 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 tests wallet_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.

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant