mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-24 14:40:12 +01:00
blockstorage: Return on fatal block file flush error
By returning an error code if `FlushBlockFile` fails, the caller now has to explicitly handle block file flushing errors. Before this change such errors were non-explicitly ignored without a clear rationale. Prior to this patch `FlushBlockFile` may have failed silently in `Chainstate::FlushStateToDisk`. Improve this with a log line. Also add a TODO comment to flesh out whether returning early in the case of an error is appropriate or not. Returning early might be appropriate to prohibit `WriteBlockIndexDB` from writing a block index entry that does not refer to a fully flushed block. Besides `Chainstate::FlushStateToDisk`, `FlushBlockFile` is also called by `FindBlockPos`. Don't change the abort behavior there, since we don't want to fail the function if the flushing of already written blocks fails. Instead, just document it.
This commit is contained in:
@@ -2511,7 +2511,11 @@ bool Chainstate::FlushStateToDisk(
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("write block and undo data to disk", BCLog::BENCH);
|
||||
|
||||
// First make sure all block and undo data is flushed to disk.
|
||||
m_blockman.FlushBlockFile();
|
||||
// TODO: Handle return error, or add detailed comment why it is
|
||||
// safe to not return an error upon failure.
|
||||
if (!m_blockman.FlushBlockFile()) {
|
||||
LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Warning, "%s: Failed to flush block file.\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
// Then update all block file information (which may refer to block and undo files).
|
||||
|
||||
Reference in New Issue
Block a user