diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-01-27 00:22:15 +0100 |
---|---|---|
committer | Pieter Wuille <pieterw@google.com> | 2013-01-30 03:56:45 +0100 |
commit | 18379c80874ad6f4fa0e962dd2046e2fa7ecd287 (patch) | |
tree | a60dfa3a57c9195d2583b6cb45879658d319c8a3 | |
parent | 86c82bf9d09f4b3f9c29cc49a4615efd8c60a152 (diff) |
Add disk space checks before flushing CCoins cache
-rw-r--r-- | src/main.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 1d881c0a35..2b4acccb9e 100644 --- a/src/main.cpp +++ b/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 bool fIsInitialDownload = IsInitialBlockDownload(); 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(); pblocktree->Sync(); if (!pcoinsTip->Flush()) |