Fixes #28898
When importing descriptors, users may accidentally provide an incorrect birthdate (timestamp). This can cause the wallet to miss relevant historical transactions, leading to incorrect or incomplete balances. Currently, the wallet only relies on rescans starting from the provided timestamp.
This PR extends the importdescriptors RPC with a new optional argument:
scan_utxoset
(bool, default=false):
If enabled, the wallet will compare its calculated trusted balance against UTXO set balance (by generating the scriptpukeys
of the wallet and comparing it with the chains UTXO set scriptpubkeys
to get the accurate balance belonging to the wallet and comparing it with the wallet trusted balance).
If the balances match, import continues as normal. If a discrepancy is detected, the wallet will attempt incremental rescans in chunks of recent blocks until the missing history is found. If the wallet is pruned, incremental rescans will not go earlier than the prune boundary.
Additional information is returned in the RPC response under an "info"
object when scan_utxoset
is used, such as:
utxo_check
: whether the UTXO set matched the wallet balance
scanned_chunks:
number of incremental rescan chunks attempted
scanned_blocks
: approximate number of blocks scanned during incremental rescans
This helps detect and fix balance mismatches caused by wrong descriptor timestamps.
A big thanks to fjahr for suggesting this approach comment