work in trustnote(3)

Catchup

In Bitcoin, there is two kind of catchup:

  • Small catchup
  • Large catchup

Small catchup

  • Downloader sends getblocks(locator(dChainHead), 0)
  • Responder sends invs for blocks from dChainHead to rChainHead
  • Downloader sends getdata for each inv
  • Responder sends blocks for each getdata

Large catchup

  • Downloader sends getblocks(locator(dChainHead), 0)
  • Responder sends invs for blocks from dChainHead to dChainHead + 500
  • (getdata / blocks sent by responder / blocks added to chain by downloader)
  • The last getdata triggers an inv(rChainHead)
  • Downloader sends getdata(rChainHead)
  • Responder sends block
  • Downloader puts block on orphan list
  • Downloader sends getblocks(locator(dChainHead), rChainHead)
  • goto step 2

The first thing bitcoin get is a chain that build by headers. And the most interesting thing about it is that we don’t need to care about the transations inside the block. We only need to verify that this block is valid. But why?

The header of bitcoin is :

Field Purpose Updated when… Size (Bytes)
Version Block version number You upgrade the software and it specifies a new version 4
hashPrevBlock 256-bit hash of the previous block header A new block comes in 32
hashMerkleRoot 256-bit hash based on all of the transactions in the block A transaction is accepted 32
Time Current timestamp as seconds since 1970-01-01T00:00 UTC Every few seconds 4
Bits Current target in compact format The difficulty is adjusted 4
Nonce 32-bit number (starts at 0) A hash is tried (increments) 4

So the header has everything we need to verify the block. And the we don’t need to worry about double check or bad transation, which will be verified by following blocks. And this is where magic is. A light client can also store a bitcoin’s chain in this way, and it only need to get its transations but still can verify them because of the merkle root. And a full client can get those details from different responser by different sequence and skip the validation of UTXO.