3

Let's say bitcoin node has 100 blocks. Then he recieve another two blocks. Now it have 102 blocks. But now he recieve block 103. And this block is from another chain and our node have to remove blocks 101 and 102 and replace them with this chain with block 101, 102 and 103.

So now it must rewind UTXO set back to node 100 and update with transactions from newly recieved nodes 101..103.

How nodes making this rollback in utxo set?

6

Bitcoin Core since v0.8 maintains "undo files" that contain the information necessary to undo the effect of a block on the UTXO set.

In a way you can see blocks as authenticated patches to be applied to the UTXO set; they list new outputs to be added, and which inputs to be spent. In order to support rolling back the UTXO set, undo blocks are created as a side effect of validation: structures that contain the UTXOs that were spent. When rolling back, the undo files are applied in reverse order.

  • and how was this before v0.8? and for how many blocks are undo files hold? – Michal May 26 at 20:12
  • 2
    Before 0.8 an entirely different design was used, where instead of a UTXO set, a database was kept with for every output ever created whether it was spent, and if so, where it was spent. Rolling back just required marking those database entries as unspent again. – Pieter Wuille May 26 at 20:15
  • 2
    Undo data is kept for every block that is kept (undo files are around 10x smaller than the corresponding block files). If you prune your node, both old blocks and old undo data are pruned. – Pieter Wuille May 26 at 20:16

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.