Skip to content

Commit

Permalink
Merge #2328: Always flush block and undo when switching to new file
Browse files Browse the repository at this point in the history
ab4f184 Fixed integer comparison warning. (Eric Lombrozo)
189d8b7 Always flush block and undo when switching to new file (Pieter Wuille)

Pull request description:

  Fixing a possible blocks db corruption cause.

  > Previously, the undo weren't being flushed during a reindex because
  fKnown was set to true in FindBlockPos. That is the correct behaviour
  for block files as they aren't being touched, but undo files are
  touched.

  > This changes the behavior to always flush when switching to a new file
  (even for block files, though that isn't really necessary).

  Coming from bitcoin#6948.

ACKs for top commit:
  random-zebra:
    utACK ab4f184
  Fuzzbawls:
    ACK ab4f184

Tree-SHA512: c544861e74015afab3cb7162fd49f478e455f7a7b0bfa19c9e3c74ccccd343130dab770fe5a2ad88e017889fe075da999caa89bb06dc669d41d7ba573295cbea
  • Loading branch information
furszy committed Apr 24, 2021
2 parents d1210fa + ab4f184 commit 22872bb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2629,8 +2629,6 @@ bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAdd

if (!fKnown) {
while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) {
LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString());
FlushBlockFile(true);
nFile++;
if (vinfoBlockFile.size() <= nFile) {
vinfoBlockFile.resize(nFile + 1);
Expand All @@ -2640,7 +2638,14 @@ bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAdd
pos.nPos = vinfoBlockFile[nFile].nSize;
}

nLastBlockFile = nFile;
if ((int)nFile != nLastBlockFile) {
if (!fKnown) {
LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString());
}
FlushBlockFile(!fKnown);
nLastBlockFile = nFile;
}

vinfoBlockFile[nFile].AddBlock(nHeight, nTime);
if (fKnown)
vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize);
Expand Down

0 comments on commit 22872bb

Please sign in to comment.