SaveBlockToDisk / FindBlockPos are used for two purposes, depending on whether they are called during reindexing (dbp set, fKnown = true) or in the "normal" case when adding new blocks (dbp == nullptr, fKnown = false).
The actual tasks are quite different
- In normal mode, preparations for saving a new block are made, which is then saved: find the correct position on disk (maybe skipping to a new blk file), check for available disk space, update the blockfile info db, save the block.
- during reindex, most of this is not necessary (the block is already on disk after all), only the blockfile info needs to rebuilt because reindex wiped the leveldb it's saved in.
Using one function with many conditional statements for this leads to code that is hard to read / understand and bug-prone.
This is a backport of core#29975