5

What are the steps a SPV client takes in order to sync?

  • Connect to a peer
  • Set bloom filter for wallet addresses
  • Download all block-headers since latest checkpoint
  • Request every block again with filters set
  • Update wallet balance based on returned blocks

Obviously the above steps are wrong since it makes no sense to first download all blockheaders to determine the correct chain, and then re-request all blocks to calculate the wallet balance.

But what is the correct procedure?

4

This is what I do:

  1. Connect to peer
  2. Set bloom filter
  3. Send 'getblocks' message
  4. Send 'getdata' message with MSG_FILTERED_BLOCK set for any new blocks

Note that 'getblocks' returns a list of block chain hashes from the specified starting point, not the blocks themselves. Then 'getdata' returns 'merkleblock' messages instead of full blocks. The peer follows the 'merkleblock' message with any transactions that match the bloom filter as separate 'tx' messages.

More details are in BIP0037

If you want an example, my Java wallet can be found on GitHub

1

A couple examples may help you:

https://code.google.com/p/bitcoinj/

My project https://github.com/richardkiss/pycoinnet is not complete (in particular, as of this writing, there is no bloom filter implementation), but it may eventually do what you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.