There have been multiple questions on this but none, IMO, really get to the issue:
- The rev*.dat files hold "undo" data for rolling back the UTXO state, block by block,
- and they're 1::1 with block files (i.e., for a given NNNNN the files
revNNNNN.dathold information for the same blocks),
- and they're written and chunked in the order in which blocks are received by the node (from the network)
- and the UTXO set is computed (can only be computed) by considering blocks in block-chain order,
- and in any block the coinbase transaction is unspendable for 101 confirmations (by consensus) which is so that reorgs of up to 100 blocks don't cause serious problems with coins suddenly disappearing, and 100 blocks piled on top is apparently long enough to outwait any reorganization ...
Then: Are very old rev*.dat files ever used? Say, those that belong to blocks buried more than 100 blocks deep from the top of the chain? If they are ever used what is the use case?
(and, w.r.t. the answer here of the first question in the following list, what is the database corruption that occurs - presumably to the UTXO state - if the rev files are all deleted and why is it necessary to regenerate them?)
(bonus question: given a txindex: is there anything in the rev*.dat file that can't be regenerated simply by looking at the blocks in the corresponding blk*.dat file and using the txindex to find previous transactions?
Other questions here approaching this question but not dupes:
- "Are old rev*.dat file safely deletable?" - closest to being on point, the accepted answer explains (without really explaining) that if you delete them it "effectively corrupts the databases" and also that they'll be recreated if they're all deleted. But doesn't say why they need to be kept indefinitely, which is what I'm asking.
- "What exactly are the rev00000.dat files?" - directly answers what they're for but does not answer why they need to be kept forever
- "File format -- rev*.dat" - specifically about the format of the contents of the rev files
- "What's raw undo data for?" - sadly, the only answer doesn't even answer the question asked but is in fact a cut/paste of the answer to the file format question #57978 directly above in this list - yet, it got the OP's checkmark, go figure...
- "Undo files format change and reorg process question for v0.19" - extremely detailed answer about the format of the contents of the rev files
- The tag "undofiles" - 3 questions (before this one) - 2 are listed above and the other is someone's one-off operational problem (blank blk and rev files).
- This answer is very good as to when rev*.dat files are used (blockchain reorgs) but doesn't address why they're kept forever.