<p>Indeed, you can consider transactions to be 'patches' against the set of unspent outputs (the UTXO set): they consume some outputs, and they create some new outputs. Blocks are aggregated patches.</p>

<p>And indeed, to be able to undo the effects of a block on the UTXO set, a record with the reverse patch is written to the rev*.dat files (corresponding to the blocks in the same blk*.dat file).</p>

<p>The format is custom and very compact. For every transaction input (excluding the coinbase's, which does not spend anything) it contains the script and amount of the output being spent and whether it was created by a coinbase. If the output was the last of a particular transaction being spent, the transaction version and height in the chain it was created at are also stored.</p>

CC BY-SA 3.0
2014-11-26T16:59:12.493Z
I'm going to accept this answer, but I was hoping for more detail on the format itself. It seems spectacularly compact, at roughly 18 megs~ per file that seems like far less than would be necessary to revert a lot of one meg blocks.  Unless I misunderstood and the rev patch doesn't rewind a block as a single block at a time but instead rewinds in a single patch N blocks back then forward applies the correct chain?
Matt
CC BY-SA 3.0
2014-11-26T17:53:50.210Z
No, it contains one record per block, which is individually applied when rolling back.
Pieter Wuille
CC BY-SA 3.0
2014-11-26T00:47:55.800Z
2014-11-26T00:47:55.800Z
Pieter Wuille
<p>I've been looking at the on disk structured generated by the standard bitcoin-qt client. It looks to me that the rev?????.dat files are reverse application for blocks? So I imagine every single spent output is added to the reverse dat, so that they can be applied directly to the unspent pool during a rewind?</p>

<p>What exactly is stored, and what is the format? </p>

<bitcoin-core><undofiles>
What exactly are the rev00000.dat files?
Matt
# What exactly are the rev00000.dat files?

(Asked by: username_0 on 2014-11-25)

I've been looking at the on disk structured generated by the standard bitcoin-qt client. It looks to me that the rev?????.dat files are reverse application for blocks? So I imagine every single spent output is added to the reverse dat, so that they can be applied directly to the unspent pool during a rewind?

What exactly is stored, and what is the format?

**Tags:** bitcoin-core, undofiles


---

## 1 answers

### Answer by username_1 on 2014-11-26. Score: 3 | Accepted answer

Indeed, you can consider transactions to be 'patches' against the set of unspent outputs (the UTXO set): they consume some outputs, and they create some new outputs. Blocks are aggregated patches.

And indeed, to be able to undo the effects of a block on the UTXO set, a record with the reverse patch is written to the rev\*.dat files (corresponding to the blocks in the same blk\*.dat file).

The format is custom and very compact. For every transaction input (excluding the coinbase's, which does not spend anything) it contains the script and amount of the output being spent and whether it was created by a coinbase. If the output was the last of a particular transaction being spent, the transaction version and height in the chain it was created at are also stored.

> **Comments:**
> **username_0**: I'm going to accept this answer, but I was hoping for more detail on the format itself. It seems spectacularly compact, at roughly 18 megs~ per file that seems like far less than would be necessary to revert a lot of one meg blocks.  Unless I misunderstood and the rev patch doesn't rewind a block as a single block at a time but instead rewinds in a single patch N blocks back then forward applies the correct chain?  
> **username_1**: No, it contains one record per block, which is individually applied when rolling back.  

---

