Revives #20664. All feedback from the previous PR has either been responded to inline or incorporated here.
Major changes from Jonas’ PR:
- consolidated arguments for scantxoutset/scanblocks
- substantial cleanup of the functional test
Here’s the range-diff (git range-diff master jonasschnelli/2020/12/filterblocks_rpc jamesob/2021-11-scanblocks
): https://gist.github.com/jamesob/aa4a975344209f0316444b8de2ec1d18
Original PR description
The
scanblocks
RPC call allows one to get relevant blockhashes from a set of descriptors by scanning all blockfilters in a given range.Example:
scanblocks start '["addr(<bitcoin_address>)"]' 661000
(returns relevant blockhashes for<bitcoin_address>
from blockrange 661000->tip)Why is this useful?
Fast wallet rescans: get the relevant blocks and only rescan those via
rescanblockchain getblockheader(<hash>)[height] getblockheader(<hash>)[height])
. A future PR may add an option to allow to provide an array of blockhashes torescanblockchain
.prune wallet rescans: (needs additional changes): together with a call to fetch blocks from the p2p network if they have been pruned, it would allow to rescan wallets back to the genesis block in pruned mode (relevant #15946).
SPV mode (needs additional changes): it would be possible to build the blockfilterindex from the p2p network (rather then deriving them from the blocks) and thus allow some sort of hybrid-SPV mode with moderate bandwidth consumption (related #9483)