message: Always flush DB if a new block file begins
diff: @@ -2667,12 +2667,17 @@ bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, CBlock*
  int64_t nTime4 = GetTimeMicros();
  nTimeFlush += nTime4 - nTime3;
  LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);
  - // Write the chain state to disk, if necessary.
  - if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
  +
  + // Write the chain state to disk, if necessary. Always write to disk if this is the first of a new file.
  + FlushStateMode flushMode = FLUSH_STATE_IF_NEEDED;
  + if (pindexNew->GetBlockPos().nFile != pindexNew->pprev->GetBlockPos().nFile)
  + flushMode = FLUSH_STATE_ALWAYS;
  + if (!FlushStateToDisk(state, flushMode))
  return false;
  int64_t nTime5 = GetTimeMicros();
  nTimeChainState += nTime5 - nTime4;
  LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
  +
  // Remove conflicting transactions from the mempool.
  list<CTransaction> txConflicted;
  mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, txConflicted);
  