Repository navigation
wallet, rpc: add verify_balance option to importdescriptors - #36236
musaHaruna wants to merge 4 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible typos and grammar issues:
Possible places where comparison-specific test macros should replace generic comparisons:
2026-09-17 20:08:47 |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
ab6fb97 to
904ed16
Compare
904ed16 to
3eccd34
Compare
Add an interface function to scan the chainstate for coins matching the requested output scripts, fill the output map with matching coins, and set the best block of the scanned snapshot.
Collect unique scripts from the wallet's script managers and scan chainstate for matching unspent outputs. Filter out coinbase outputs that are immature at the scanned block height. Return the matching coins, searched scripts, and the scan's block hash and height so callers can identify missing outputs and report which chainstate was scanned.
Add an optional verify_balance argument to check the wallet's confirmed mature UTXOs against a chainstate scan for known wallet scripts. If the wallet is missing outputs, extend the rescan to the earliest missing output when it is before the requested scan start. Keep the requested timestamp range so older transaction history is still scanned. Return the comparison result, UTXO counts and scan details. Verification failures leave descriptors and any discovered transactions in the wallet. The option defaults to false.
Cover missing UTXO recovery, timestamp handling, mismatch reporting and mempool transactions. Check that pruned blocks fail verification without removing the imported descriptor.
3eccd34 to
4da013f
Compare
musaHaruna
left a comment
There was a problem hiding this comment.
Rebased on the latest master and resolved the conflict with #34861.
Since #34861 moved descriptor importing and rescanning into the shared importer, I moved the UTXO verification scan into src/wallet/imports.cpp as well. The RPC now passes verify_balance to ProcessDescriptorsImport(...), and backup.cpp only handles parsing the RPC argument and formatting the result. compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
Following what I said in #28898 (comment) I tend to concept NACK. |
|
Thanks @polespinasa for the feedback.
I think this could be nice to have. I’ll close this PR and plan to open another with the above suggested approach. Before opening a replacement PR, I’ll benchmark UTXO set scans to assess whether the performance cost is acceptable for a default check. |

Another Attempt to fix #28898
When importing descriptors, users may provide a timestamp that is too recent. This causes the rescan to miss older payments, leaving the wallet with an incomplete balance.
This PR adds an optional
verify_balanceargument to importdescriptors, which is false by default.When enabled, it scans the chainstate UTXO set once for outputs belonging to the wallet’s known scripts. If it finds outputs missing from the wallet, it uses the earliest missing output’s block height to extend the rescan backwards where needed, then scans forward. An earlier requested timestamp is still respected so older transaction history is scanned as well.
After rescanning, it compares the wallet’s confirmed mature UTXO outpoints with those collected from the initial chainstate scan. The response includes an info object showing the verification result, UTXO counts and scan details.
For example:
Example response when verification recovers payments:
[ { "success": true, "info": { "status": "matched after recovery", "utxo_check": true, "scanned_blocks": 22, "wallet_utxos": 2, "chain_utxos": 2, "scan_start_height": 101, "snapshot_block": "0000000000000001234..01f", "snapshot_height": 122, "recovery_start_height": 101 } } ]If the sets still differ, verification reports
"utxo_check": falsewith an error explaining the mismatch. For example, the info object may contain:Failure Response
{ "status": "unmatched", "utxo_check": false, "scanned_blocks": 22, "wallet_utxos": 2, "chain_utxos": 1, "scan_start_height": 101, "snapshot_block": "00000000000000001234...01f", "snapshot_height": 122, "recovery_start_height": 101 }Verification failures leave the descriptors imported and keep any transactions already discovered. Required blocks being unavailable is reported explicitly. No automatic retry or fallback rescan is performed.
A match verifies the compared UTXO sets; it does not guarantee complete transaction history. Older spent transactions still require an appropriate timestamp or a full rescan. Changes to relevant UTXOs during verification can also cause a mismatch because the final wallet check is compared with the initial chainstate scan.
Functional tests cover recovery with recent timestamps, preserving older requested history, mismatches, mempool transactions, invalid requests and unavailable blocks.