message: Relocate calls to CheckDiskSpace
  Make sure we're checking disk space for block index writes and allow for pruning to happen before chainstate writes.
  Coming from upstream@86a5f4b54ebf5f3251f4c172cf9a5041ae43c082
diff: @@ -2613,12 +2613,8 @@ bool static FlushStateToDisk(CValidationState& state, FlushStateMode mode)
  bool fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush;
  // Write blocks and block index to disk.
  if (fDoFullFlush || fPeriodicWrite) {
  - // Typical CCoins structures on disk are around 128 bytes in size.
  - // Pushing a new one to the database can cause it to be written
  - // twice (once in the log, and once in the tables). This is already
  - // an overestimation, as most will delete an existing entry or
  - // overwrite one. Still, use a conservative safety factor of 2.
  - if (fDoFullFlush && !CheckDiskSpace(128 * 2 * 2 * pcoinsTip->GetCacheSize()))
  + // Depend on nMinDiskSpace to ensure we can write block index
  + if (!CheckDiskSpace(0))
  return state.Error("out of disk space");
  // First make sure all block and undo data is flushed to disk.
  FlushBlockFile();
  @@ -2653,6 +2649,13 @@ bool static FlushStateToDisk(CValidationState& state, FlushStateMode mode)
  // Flush best chain related state. This can only be done if the blocks / block index write was also done.
  if (fDoFullFlush) {
  + // Typical CCoins structures on disk are around 128 bytes in size.
  + // Pushing a new one to the database can cause it to be written
  + // twice (once in the log, and once in the tables). This is already
  + // an overestimation, as most will delete an existing entry or
  + // overwrite one. Still, use a conservative safety factor of 2.
  + if (!CheckDiskSpace(128 * 2 * 2 * pcoinsTip->GetCacheSize()))
  + return state.Error("out of disk space");
  // Flush the chainstate (which may refer to block index entries).
  if (!pcoinsTip->Flush())
  return AbortNode(state, "Failed to write to coin database");
  