Avoid pruning headers that have not been saved to disk yet

This commit is contained in:
Pablo Greco 2023-06-29 10:43:49 -07:00 committed by James Dorfman
parent 283f47b38d
commit 423715b048
3 changed files with 20 additions and 1 deletions

View file

@ -2577,6 +2577,11 @@ bool CChainState::FlushStateToDisk(
return AbortNode(state, "Failed to write to block index database");
}
// This should be done inside WriteBatchSync, but CBlockIndex is const there
for (std::set<CBlockIndex*>::iterator it = setTrimmableBlockIndex.begin(); it != setTrimmableBlockIndex.end(); it++) {
(*it)->set_stored();
}
if (node::fTrimHeaders) {
LogPrintf("Flushing block index, trimming headers, setTrimmableBlockIndex.size(): %d\n", setTrimmableBlockIndex.size());
int trim_height = m_chain.Height() - node::nMustKeepFullHeaders;