HomePhabricator

Explicitly track maximum block height stored in undo files

Description

Explicitly track maximum block height stored in undo files

Summary:
When writing a new block to disk, if we have filled up the current block file,
then we flush and truncate that block file (to free allocated but unused
space) before advancing to the next one. When this happens, we have to
determine whether to also flush and truncate the corresponding undo file.

Undo data is only written when blocks are connected, not when blocks are
received. Thus it's possible that the corresponding undo file already has all
the data it will ever have, and we should flush/truncate it as we advance
files; or it's possible that there is more data we expect to write, and should
therefore defer flush/truncation until undo data is later written.

Prior to this commit, we made the determination of whether the undo file was
full of all requisite data by comparing against the chain tip. This patch
replaces that dependence on validation data structures by instead just tracking
the highest height of any block written in the undo file as we go.

Thiss removes the CChain dependency in node/blockstorage

This is a partial backport of core#27746
https://github.com/bitcoin/bitcoin/pull/27746/commits/fe86a7cd480b32463da900db764d2d11a2bea095
https://github.com/bitcoin/bitcoin/pull/27746/commits/1cfc887d00c5d1d4281107e3b3ff4641c6c34631

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D17432

Details

Provenance
Suhas Daftuar <sdaftuar@chaincode.com>Authored on Apr 28 2023, 22:50
PiRKCommitted on Fri, Jan 17, 08:07
PiRKPushed on Fri, Jan 17, 08:07
Reviewer
Restricted Project
Differential Revision
D17432: Explicitly track maximum block height stored in undo files
Parents
rABCd2683db55d84: [test] Make test_getpeerinfo more robust by using mocktime
Branches
Unknown
Tags
Unknown