diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2015-03-06 20:26:09 -0500 |
---|---|---|
committer | Cory Fields <cory-nospam-@coryfields.com> | 2015-03-10 13:59:46 -0400 |
commit | bb6acff07982dda68b5c2ac81c99dbd7255bb9cc (patch) | |
tree | 00eb1a97470a5e8d3728c9d00908d5ff5274d285 | |
parent | 7c3fbc34aed578398b3f180a621c671ff3837cec (diff) |
fix possible block db breakage during re-index
When re-indexing, there are a few cases where garbage data may be skipped in
the block files. In these cases, the indices are correctly written to the index
db, however the pointer to the next position for writing in the current block
file is calculated by adding the sizes of the valid blocks found.
As a result, when the re-index is finished, the index db is correct for all
existing blocks, but the next block will be written to an incorrect offset,
likely overwriting existing blocks.
Rather than using the sum of all valid blocks to determine the next write
position, use the end of the last block written to the file. Don't assume that
the current block is the last one in the file, since they may be read
out-of-order.
-rw-r--r-- | src/main.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 9927ac7598..183dff6d39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2455,8 +2455,11 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd } nLastBlockFile = nFile; - vinfoBlockFile[nFile].nSize += nAddSize; vinfoBlockFile[nFile].AddBlock(nHeight, nTime); + if (fKnown) + vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize); + else + vinfoBlockFile[nFile].nSize += nAddSize; if (!fKnown) { unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |