0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

log: LogError with FlatFilePos in UndoReadFromDisk

These errors should never happen in normal operation. If they do,
knowing the FlatFilePos may be useful to determine if data corruption
happened. Also, handle the error pos.IsNull() as part of OpenUndoFile,
because it may as well have happened due to data corruption.

This mirrors the LogError behavior from ReadBlockFromDisk.
This commit is contained in:
MarcoFalke 2024-07-11 16:20:06 +02:00
parent aaaa3323f3
commit fad59a2f0f
No known key found for this signature in database

View file

@ -703,15 +703,10 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
{
const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
if (pos.IsNull()) {
LogError("%s: no undo data available\n", __func__);
return false;
}
// Open history file to read
AutoFile filein{OpenUndoFile(pos, true)};
if (filein.IsNull()) {
LogError("%s: OpenUndoFile failed\n", __func__);
LogError("%s: OpenUndoFile failed for %s\n", __func__, pos.ToString());
return false;
}
@ -723,13 +718,13 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
verifier >> blockundo;
filein >> hashChecksum;
} catch (const std::exception& e) {
LogError("%s: Deserialize or I/O error - %s\n", __func__, e.what());
LogError("%s: Deserialize or I/O error - %s at %s\n", __func__, e.what(), pos.ToString());
return false;
}
// Verify checksum
if (hashChecksum != verifier.GetHash()) {
LogError("%s: Checksum mismatch\n", __func__);
LogError("%s: Checksum mismatch at %s\n", __func__, pos.ToString());
return false;
}