Closes #2039
When reindexing from flat-file block storage there is no need to write anything back to disk, since the block data is already there. This PR skips flushing to disk those blocks that already have a known position in the datastore. Skipping this means that users can write-protect the blk
files on disk which may be useful for security or even safely sharing that data between multiple bitcoind instances.
FindBlockPos()
may also flush the undo data file, but again this is skipped if the corresponding block position is known, like during the initial stage of a reindex when block data is being indexed. Once the block index is complete the validation mechanism will call ConnectBlock()
which will save undo data at that time.
The call stack looks like this:
0init()
1ThreadImport() <-- process fReindex flag
2LoadExternalBlockFile()
3AcceptBlock()
4SaveBlockToDisk()
5FindBlockPos()
6FlushBlockFile() <-- unnecessary if block is already on disk
A larger refactor of this part of the code was started by mzumsande here: https://github.com/mzumsande/bitcoin/tree/202207_refactor_findblockpos including this fix, reviewers can let me know if the changes should be combined.