Skip to content

Commit a8e9baa

Browse files
committed
Relocate calls to CheckDiskSpace
Make sure we're checking disk space for block index writes and allow for pruning to happen before chainstate writes.
1 parent 67708ac commit a8e9baa

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,12 +1919,8 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19191919
bool fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
19201920
// Write blocks and block index to disk.
19211921
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))
19281924
return state.Error("out of disk space");
19291925
// First make sure all block and undo data is flushed to disk.
19301926
FlushBlockFile();
@@ -1955,6 +1951,13 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19551951
}
19561952
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
19571953
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");
19581961
// Flush the chainstate (which may refer to block index entries).
19591962
if (!pcoinsTip->Flush())
19601963
return state.Abort("Failed to write to coin database");

0 commit comments

Comments
 (0)