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

<p>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.</p>

CC BY-SA 4.0
2019-05-26T20:12:59.577Z
and how was this before v0.8? and for how many blocks are undo files hold?
Michal
CC BY-SA 4.0
2019-05-26T20:15:23.957Z
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
CC BY-SA 4.0
2019-05-26T20:16:21.077Z
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
CC BY-SA 4.0
2019-05-26T17:47:15.217Z
2019-05-26T17:47:15.217Z
Pieter Wuille
<p>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.</p>

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

<p>How nodes making this rollback in utxo set?</p>

<blockchain-fork><utxo><utxo-set>
How bitcoin nodes update UTXO set when their latests blocks are replaced?
Michal
# How bitcoin nodes update UTXO set when their latests blocks are replaced?

(Asked by: username_0 on 2019-05-26)

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?

**Tags:** blockchain-fork, utxo, utxo-set


---

## 1 answers

### Answer by username_1 on 2019-05-26. Score: 7

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.

> **Comments:**
> **username_0**: and how was this before v0.8? and for how many blocks are undo files hold?  
> **username_1**: 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.  
> **username_1**: 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.  

---

