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