Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CBlockFileInfo
unsigned int nHeightLast; //!< highest height of block in file
uint64_t nTimeFirst; //!< earliest time of block in file
uint64_t nTimeLast; //!< latest time of block in file
bool modified; //!< (memory only) whether the file has been modified

SERIALIZE_METHODS(CBlockFileInfo, obj)
{
Expand All @@ -71,6 +72,7 @@ class CBlockFileInfo
nHeightLast = 0;
nTimeFirst = 0;
nTimeLast = 0;
modified = false;
}

CBlockFileInfo()
Expand Down
10 changes: 7 additions & 3 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,13 @@ void BlockManager::FlushBlockFile(bool fFinalize, bool finalize_undo)
}
assert(static_cast<int>(m_blockfile_info.size()) > m_last_blockfile);

FlatFilePos block_pos_old(m_last_blockfile, m_blockfile_info[m_last_blockfile].nSize);
if (!BlockFileSeq().Flush(block_pos_old, fFinalize)) {
AbortNode("Flushing block file to disk failed. This is likely the result of an I/O error.");
if (m_blockfile_info[m_last_blockfile].modified) {
FlatFilePos block_pos_old(m_last_blockfile, m_blockfile_info[m_last_blockfile].nSize);
if (!BlockFileSeq().Flush(block_pos_old, fFinalize)) {
AbortNode("Flushing block file to disk failed. This is likely the result of an I/O error.");
}
}

// we do not always flush the undo file, as the chain tip may be lagging behind the incoming blocks,
// e.g. during IBD or a sync after a node going offline
if (!fFinalize || finalize_undo) FlushUndoFile(m_last_blockfile, finalize_undo);
Expand Down Expand Up @@ -821,6 +824,7 @@ FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CCha
AbortNode("Failed to write block");
return FlatFilePos();
}
m_blockfile_info[blockPos.nFile].modified = true;
}
return blockPos;
}
Expand Down