@@ -2134,8 +2134,9 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
2134
2134
// Write blocks and block index to disk.
2135
2135
if (fDoFullFlush || fPeriodicWrite ) {
2136
2136
// Depend on nMinDiskSpace to ensure we can write block index
2137
- if (!CheckDiskSpace (0 , true ))
2138
- return state.Error (" out of disk space" );
2137
+ if (!CheckDiskSpace (GetBlocksDir ())) {
2138
+ return AbortNode (state, " Disk space is low!" , _ (" Error: Disk space is low!" ));
2139
+ }
2139
2140
// First make sure all block and undo data is flushed to disk.
2140
2141
FlushBlockFile ();
2141
2142
// Then update all block file information (which may refer to block and undo files).
@@ -2168,8 +2169,9 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
2168
2169
// twice (once in the log, and once in the tables). This is already
2169
2170
// an overestimation, as most will delete an existing entry or
2170
2171
// overwrite one. Still, use a conservative safety factor of 2.
2171
- if (!CheckDiskSpace (48 * 2 * 2 * pcoinsTip->GetCacheSize ()))
2172
- return state.Error (" out of disk space" );
2172
+ if (!CheckDiskSpace (GetDataDir (), 48 * 2 * 2 * pcoinsTip->GetCacheSize ())) {
2173
+ return AbortNode (state, " Disk space is low!" , _ (" Error: Disk space is low!" ));
2174
+ }
2173
2175
// Flush the chainstate (which may refer to block index entries).
2174
2176
if (!pcoinsTip->Flush ())
2175
2177
return AbortNode (state, " Failed to write to coin database" );
@@ -3014,7 +3016,7 @@ static bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int
3014
3016
if (nNewChunks > nOldChunks) {
3015
3017
if (fPruneMode )
3016
3018
fCheckForPruning = true ;
3017
- if (CheckDiskSpace (nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos , true )) {
3019
+ if (CheckDiskSpace (GetBlocksDir (), nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos )) {
3018
3020
FILE *file = OpenBlockFile (pos);
3019
3021
if (file) {
3020
3022
LogPrintf (" Pre-allocating up to position 0x%x in blk%05u.dat\n " , nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile );
@@ -3023,7 +3025,7 @@ static bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int
3023
3025
}
3024
3026
}
3025
3027
else
3026
- return error ( " out of disk space" );
3028
+ return AbortNode ( " Disk space is low! " , _ ( " Error: Disk space is low! " ) );
3027
3029
}
3028
3030
}
3029
3031
@@ -3047,16 +3049,17 @@ static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos,
3047
3049
if (nNewChunks > nOldChunks) {
3048
3050
if (fPruneMode )
3049
3051
fCheckForPruning = true ;
3050
- if (CheckDiskSpace (nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos , true )) {
3052
+ if (CheckDiskSpace (GetBlocksDir (), nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos )) {
3051
3053
FILE *file = OpenUndoFile (pos);
3052
3054
if (file) {
3053
3055
LogPrintf (" Pre-allocating up to position 0x%x in rev%05u.dat\n " , nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile );
3054
3056
AllocateFileRange (file, pos.nPos , nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos );
3055
3057
fclose (file);
3056
3058
}
3057
3059
}
3058
- else
3059
- return state.Error (" out of disk space" );
3060
+ else {
3061
+ return AbortNode (state, " Disk space is low!" , _ (" Error: Disk space is low!" ));
3062
+ }
3060
3063
}
3061
3064
3062
3065
return true ;
@@ -3763,17 +3766,6 @@ static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfte
3763
3766
nLastBlockWeCanPrune, count);
3764
3767
}
3765
3768
3766
- bool CheckDiskSpace (uint64_t nAdditionalBytes, bool blocks_dir)
3767
- {
3768
- uint64_t nFreeBytesAvailable = fs::space (blocks_dir ? GetBlocksDir () : GetDataDir ()).available ;
3769
-
3770
- // Check for nMinDiskSpace bytes (currently 50MB)
3771
- if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes)
3772
- return AbortNode (" Disk space is low!" , _ (" Error: Disk space is low!" ));
3773
-
3774
- return true ;
3775
- }
3776
-
3777
3769
static FILE* OpenDiskFile (const CDiskBlockPos &pos, const char *prefix, bool fReadOnly )
3778
3770
{
3779
3771
if (pos.IsNull ())
0 commit comments