What exactly are the rev00000.dat files?

5

2

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?

Matt

Posted 2014-11-25T20:05:47.260

Reputation: 520

Answers

3

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.

Pieter Wuille

Posted 2014-11-25T20:05:47.260

Reputation: 54 032

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 2014-11-26T16:59:12.493

No, it contains one record per block, which is individually applied when rolling back.Pieter Wuille 2014-11-26T17:53:50.210