Skip to content

Commit 22e7807

Browse files
committed
Always flush block and undo when switching to new file
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 behaviour to always flush when switching to a new file (even for block files, though that isn't really necessary).
1 parent 193f7b5 commit 22e7807

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,8 +2517,6 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd
25172517

25182518
if (!fKnown) {
25192519
while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) {
2520-
LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString());
2521-
FlushBlockFile(true);
25222520
nFile++;
25232521
if (vinfoBlockFile.size() <= nFile) {
25242522
vinfoBlockFile.resize(nFile + 1);
@@ -2528,7 +2526,14 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd
25282526
pos.nPos = vinfoBlockFile[nFile].nSize;
25292527
}
25302528

2531-
nLastBlockFile = nFile;
2529+
if (nFile != nLastBlockFile) {
2530+
if (!fKnown) {
2531+
LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString());
2532+
}
2533+
FlushBlockFile(!fKnown);
2534+
nLastBlockFile = nFile;
2535+
}
2536+
25322537
vinfoBlockFile[nFile].AddBlock(nHeight, nTime);
25332538
if (fKnown)
25342539
vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize);

0 commit comments

Comments
 (0)