Fixes #20978
If a block was pruned, getblock
already returns a specific error: “Block not available (pruned data)”.
But if we haven’t received the full block yet (e.g. in a race with block downloading after a new block was received headers-first, or during IBD) we just return an unspecific “Block not found on disk” error and log
ERROR: ReadBlockFromDisk: OpenBlockFile failed for FlatFilePos(nFile=-1, nPos=0)
which suggest something went wrong even though this is a completely normal and expected situation.
This PR improves the error message and stops calling ReadRawBlockFromDisk()
, when we already know from the header that the block is not available on disk.
Similarly, it prevents all other rpcs from calling blockstorage read functions unless we expect the data to be there, so that LogError()
will only be thrown when there is an actual file system problem.
I’m not completely sure if the cause is important enough to change the wording of the rpc error, that some scripts may rely on.
If reviewers prefer it, an alternative solution would be to keep returning the current “Block not found on disk” error, but return it immediately instead of calling ReadRawBlockFromDisk
, which would at least prevent the log error and also be an improvement in my opinion.