Bitcoin Forum
June 15, 2024, 06:06:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What means undo data?  (Read 193 times)
Frodek (OP)
Member
**
Offline Offline

Activity: 138
Merit: 25


View Profile
November 21, 2020, 09:37:05 PM
 #1

If I used Bitcoin client several years ago, in "blocks" directory were files *.dat and *.rev. These *.rev files contains information about undo. What is mean? Blockchain data is immutable.
Now I have Litecoin client and don't see *.rev files. I analyze LevelDB data for Litecoin testnet and here is info about undo size and undo position for block. Now undo information is in *.dat files?
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 21, 2020, 09:45:45 PM
 #2

If I used Bitcoin client several years ago, in "blocks" directory were files *.dat and *.rev. These *.rev files contains information about undo. What is mean? Blockchain data is immutable.
But it can be "re-orged"...

as per the wiki, the "undo" is for rolling back the chainstate:
blocks/rev*.dat: these contain "undo" data. You can see blocks as 'patches' to the chain state (they consume some unspent outputs, and produce new ones), and see the undo data as reverse patches. They are necessary for rolling back the chainstate, which is necessary in case of reorganisations.

More indepth reading of what rev*.dat files are: https://en.bitcoin.it/wiki/Bitcoin_Core_0.11_(ch_2):_Data_Storage#Raw_undo_data_.28rev.2A.dat.29

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Frodek (OP)
Member
**
Offline Offline

Activity: 138
Merit: 25


View Profile
November 21, 2020, 10:10:56 PM
 #3

1.
Undo data is used to rollback from fork? For example: was 500000 blocks, now incoming block 500001, but is fork and incoming new 500001 and 500002.
We use 500001-rev to undo transactions?
2.
I use Litecoin client for test because Bitcoin blocks have a lot gigabytes. I don't see *.rev files but probably undo info exists. Undo information is in *.dat?, also in new Bitcoin client?.
3.
What is format of undo data?
Pmalek
Legendary
*
Offline Offline

Activity: 2800
Merit: 7200



View Profile
November 22, 2020, 12:05:53 PM
 #4

I can't help you much but to point you towards this answer by Pieter Wuille from 2017.
https://bitcoin.stackexchange.com/questions/57978/file-format-rev-dat

Actually, since it might be helpful, I will just copy the post here.

Quote
The rev*.dat files (the "undo files"), contain all UTXOs spent by the inputs of a block. It was introduced in Bitcoin Core 0.8, and contains a concatenation of records, one for each block. This mimicks the structure of the blk*.dat files which contain blocks.

Each block record consists of:

4 bytes: network magic (0xf9,0xbe,0xb4,0xd9)
4 bytes: size of the CBlockUndo record (LE32)
data_size bytes: CBlockUndo record
32 bytes: double-SHA256 of the serialized CBlockUndo record
A CBlockUndo record consists of a serialized vector of CTxUndo records, one for each transaction in the block excluding the coinbase transaction. Vector serialization first writes a CompactSize-encoded length of the number of records (the transaction count - 1, in this case), and then serialized all the records themselves sequentially.

A CTxUndo record consists of a serialized vector of CTxInUndo records, one for each input in the transaction.

A CTxInUndo record consists of:

varint: 2*height (+1 if it was a coinbase output): the height of the block that created the spent UTXO
varint: creating transaction's version [only when height > 0]
CompressedScript: spent UTXO's scriptPubKey
CompressedAmount: spent UTXO's nValue
Until Bitcoin Core 0.14.x, the height is zero for all but the last output of a given transaction being spent. In Bitcoin Core 0.15 (to be released soon), it will be present for every spend.

For more information about the detailed encodings, see the comments in the Bitcoin Core source code: CompactSize, VarInt, CompressedScript, and CompressedAmount.

Original source: https://bitcoin.stackexchange.com/questions/57978/file-format-rev-dat


.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 23, 2020, 07:56:51 PM
Last edit: November 15, 2023, 12:38:35 AM by HCP
 #5

1. Undo data is used to rollback from fork? For example: was 500000 blocks, now incoming block 500001, but is fork and incoming new 500001 and 500002.
We use 500001-rev to undo transactions?
Yes, the -rev files are used to basically rollback to the starting point where the new (longer) chain starts, and then validate the transactions in the blocks. Basically, it reverts all the spent inputs from the "old" chain back into UTXOs (unspent transaction outputs), so it can then determine whether the inputs in the transactions in the "new" blocks are actually valid etc.

Quote
2. I use Litecoin client for test because Bitcoin blocks have a lot gigabytes. I don't see *.rev files but probably undo info exists. Undo information is in *.dat?, also in new Bitcoin client?.
I haven't used Litecoin Core in about 2 years... but my leftover litecoin data directory from 2018 still has rev****.dat files in the blocks directory. I installed the latest version 0.18.1... and after it had "updated the UTXO database", the rev****.dat files still exist. So, I'm not sure why you don't have these files? Huh


Are you running in "pruned" mode? Is the highlighted box in "Settings -> Options -> Main" checked or unchecked? Huh


█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!