Browse Source

Add disk space checks before flushing CCoins cache

miguelfreitas
Pieter Wuille 12 years ago committed by Pieter Wuille
parent
commit
18379c8087
  1. 7
      src/main.cpp

7
src/main.cpp

@ -1806,6 +1806,13 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
// Make sure it's successfully written to disk before changing memory structure // Make sure it's successfully written to disk before changing memory structure
bool fIsInitialDownload = IsInitialBlockDownload(); bool fIsInitialDownload = IsInitialBlockDownload();
if (!fIsInitialDownload || pcoinsTip->GetCacheSize() > nCoinCacheSize) { if (!fIsInitialDownload || pcoinsTip->GetCacheSize() > nCoinCacheSize) {
// Typical CCoins structures on disk are around 100 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(100 * 2 * 2 * pcoinsTip->GetCacheSize()))
return state.Error();
FlushBlockFile(); FlushBlockFile();
pblocktree->Sync(); pblocktree->Sync();
if (!pcoinsTip->Flush()) if (!pcoinsTip->Flush())

Loading…
Cancel
Save