mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
reindex, log, test: fixes #21379
This fixes a blk file size calculation made during reindex that results in increased blk file malformity. The fix is to avoid double counting the size of the serialization header during reindex. This adds a unit test to reproduce the bug before the fix and to ensure that it does not recur. These changes include a log message change also so as to not be as alarming. This is a common and recoverable data corruption. These messages can now be filtered by the debug log reindex category.
This commit is contained in:
@@ -4378,7 +4378,18 @@ void CChainState::LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp)
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
LogPrintf("%s: Deserialize or I/O error - %s\n", __func__, e.what());
|
||||
// historical bugs added extra data to the block files that does not deserialize cleanly.
|
||||
// commonly this data is between readable blocks, but it does not really matter. such data is not fatal to the import process.
|
||||
// the code that reads the block files deals with invalid data by simply ignoring it.
|
||||
// it continues to search for the next {4 byte magic message start bytes + 4 byte length + block} that does deserialize cleanly
|
||||
// and passes all of the other block validation checks dealing with POW and the merkle root, etc...
|
||||
// we merely note with this informational log message when unexpected data is encountered.
|
||||
// we could also be experiencing a storage system read error, or a read of a previous bad write. these are possible, but
|
||||
// less likely scenarios. we don't have enough information to tell a difference here.
|
||||
// the reindex process is not the place to attempt to clean and/or compact the block files. if so desired, a studious node operator
|
||||
// may use knowledge of the fact that the block files are not entirely pristine in order to prepare a set of pristine, and
|
||||
// perhaps ordered, block files for later reindexing.
|
||||
LogPrint(BCLog::REINDEX, "%s: unexpected data at file offset 0x%x - %s. continuing\n", __func__, (nRewind - 1), e.what());
|
||||
}
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
|
||||
Reference in New Issue
Block a user