I'm working on my SPV library and I still have a hard time figuring how to approach the BIP32 + Bloom filters combination. Here's how I currently sync an existing HD wallet (after fast catch-up):
- Generate a number of watched look-ahead addresses (say 10).
- Load a Bloom filter with all used addresses plus look-ahead (N used + 10 look-ahead).
- Download filtered blocks with
- Mark watched addresses as used if they're found in any block transaction.
- Ensure that the last watched address wasn't used in a transaction.
- If so, generate new look-ahead addresses, reload the Bloom filter and download last block again to rematch it. By using a new receive address for each transaction we may have missed other transactions in the same block.
- Otherwise, go back to 4 and download new blocks.
Now this sounds quirky and overcomplicated to me. Several discussions on the web talk about "scanning keys" when coming to wallet sync and I don't really understand if they assume a full node or a lightweight SPV node, because I have no idea of how to "scan keys" without a global UTXO database. Also the gap limit only seems to make sense for a full node.
I'm stuck, thanks.