@@ -1919,12 +1919,8 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
1919
1919
bool fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune ;
1920
1920
// Write blocks and block index to disk.
1921
1921
if (fDoFullFlush || fPeriodicWrite ) {
1922
- // Typical CCoins structures on disk are around 128 bytes in size.
1923
- // Pushing a new one to the database can cause it to be written
1924
- // twice (once in the log, and once in the tables). This is already
1925
- // an overestimation, as most will delete an existing entry or
1926
- // overwrite one. Still, use a conservative safety factor of 2.
1927
- if (fDoFullFlush && !CheckDiskSpace (128 * 2 * 2 * pcoinsTip->GetCacheSize ()))
1922
+ // Depend on nMinDiskSpace to ensure we can write block index
1923
+ if (!CheckDiskSpace (0 ))
1928
1924
return state.Error (" out of disk space" );
1929
1925
// First make sure all block and undo data is flushed to disk.
1930
1926
FlushBlockFile ();
@@ -1955,6 +1951,13 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
1955
1951
}
1956
1952
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
1957
1953
if (fDoFullFlush ) {
1954
+ // Typical CCoins structures on disk are around 128 bytes in size.
1955
+ // Pushing a new one to the database can cause it to be written
1956
+ // twice (once in the log, and once in the tables). This is already
1957
+ // an overestimation, as most will delete an existing entry or
1958
+ // overwrite one. Still, use a conservative safety factor of 2.
1959
+ if (!CheckDiskSpace (128 * 2 * 2 * pcoinsTip->GetCacheSize ()))
1960
+ return state.Error (" out of disk space" );
1958
1961
// Flush the chainstate (which may refer to block index entries).
1959
1962
if (!pcoinsTip->Flush ())
1960
1963
return state.Abort (" Failed to write to coin database" );
0 commit comments