Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,099 Lines • ▼ Show 20 Lines | try { | ||||
mode == FlushStateMode::PERIODIC && | mode == FlushStateMode::PERIODIC && | ||||
nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000; | nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000; | ||||
// Combine all conditions that result in a full cache flush. | // Combine all conditions that result in a full cache flush. | ||||
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || | fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || | ||||
fCacheCritical || fPeriodicFlush || fFlushForPrune; | fCacheCritical || fPeriodicFlush || fFlushForPrune; | ||||
// Write blocks and block index to disk. | // Write blocks and block index to disk. | ||||
if (fDoFullFlush || fPeriodicWrite) { | if (fDoFullFlush || fPeriodicWrite) { | ||||
// Depend on nMinDiskSpace to ensure we can write block index | // Depend on nMinDiskSpace to ensure we can write block index | ||||
if (!CheckDiskSpace(0)) { | if (!CheckDiskSpace(0, true)) { | ||||
return state.Error("out of disk space"); | return state.Error("out of disk space"); | ||||
} | } | ||||
// First make sure all block and undo data is flushed to disk. | // First make sure all block and undo data is flushed to disk. | ||||
FlushBlockFile(); | FlushBlockFile(); | ||||
// Then update all block file information (which may refer to | // Then update all block file information (which may refer to | ||||
// block and undo files). | // block and undo files). | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,305 Lines • ▼ Show 20 Lines | if (!fKnown) { | ||||
unsigned int nNewChunks = | unsigned int nNewChunks = | ||||
(vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / | (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / | ||||
BLOCKFILE_CHUNK_SIZE; | BLOCKFILE_CHUNK_SIZE; | ||||
if (nNewChunks > nOldChunks) { | if (nNewChunks > nOldChunks) { | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
fCheckForPruning = true; | fCheckForPruning = true; | ||||
} | } | ||||
if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos)) { | if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos, | ||||
true)) { | |||||
FILE *file = OpenBlockFile(pos); | FILE *file = OpenBlockFile(pos); | ||||
if (file) { | if (file) { | ||||
LogPrintf( | LogPrintf( | ||||
"Pre-allocating up to position 0x%x in blk%05u.dat\n", | "Pre-allocating up to position 0x%x in blk%05u.dat\n", | ||||
nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); | nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); | ||||
AllocateFileRange(file, pos.nPos, | AllocateFileRange(file, pos.nPos, | ||||
nNewChunks * BLOCKFILE_CHUNK_SIZE - | nNewChunks * BLOCKFILE_CHUNK_SIZE - | ||||
pos.nPos); | pos.nPos); | ||||
Show All 24 Lines | unsigned int nOldChunks = | ||||
(pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; | (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; | ||||
unsigned int nNewChunks = | unsigned int nNewChunks = | ||||
(nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; | (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; | ||||
if (nNewChunks > nOldChunks) { | if (nNewChunks > nOldChunks) { | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
fCheckForPruning = true; | fCheckForPruning = true; | ||||
} | } | ||||
if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) { | if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos, true)) { | ||||
FILE *file = OpenUndoFile(pos); | FILE *file = OpenUndoFile(pos); | ||||
if (file) { | if (file) { | ||||
LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", | LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", | ||||
nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); | nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); | ||||
AllocateFileRange(file, pos.nPos, | AllocateFileRange(file, pos.nPos, | ||||
nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); | nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); | ||||
fclose(file); | fclose(file); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 873 Lines • ▼ Show 20 Lines | static void FindFilesToPrune(std::set<int> &setFilesToPrune, | ||||
LogPrint(BCLog::PRUNE, | LogPrint(BCLog::PRUNE, | ||||
"Prune: target=%dMiB actual=%dMiB diff=%dMiB " | "Prune: target=%dMiB actual=%dMiB diff=%dMiB " | ||||
"max_prune_height=%d removed %d blk/rev pairs\n", | "max_prune_height=%d removed %d blk/rev pairs\n", | ||||
nPruneTarget / 1024 / 1024, nCurrentUsage / 1024 / 1024, | nPruneTarget / 1024 / 1024, nCurrentUsage / 1024 / 1024, | ||||
((int64_t)nPruneTarget - (int64_t)nCurrentUsage) / 1024 / 1024, | ((int64_t)nPruneTarget - (int64_t)nCurrentUsage) / 1024 / 1024, | ||||
nLastBlockWeCanPrune, count); | nLastBlockWeCanPrune, count); | ||||
} | } | ||||
bool CheckDiskSpace(uint64_t nAdditionalBytes) { | bool CheckDiskSpace(uint64_t nAdditionalBytes, bool blocks_dir) { | ||||
uint64_t nFreeBytesAvailable = fs::space(GetDataDir()).available; | uint64_t nFreeBytesAvailable = | ||||
fs::space(blocks_dir ? GetBlocksDir() : GetDataDir()).available; | |||||
// Check for nMinDiskSpace bytes (currently 50MB) | // Check for nMinDiskSpace bytes (currently 50MB) | ||||
if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) { | if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) { | ||||
return AbortNode("Disk space is low!", _("Error: Disk space is low!")); | return AbortNode("Disk space is low!", _("Error: Disk space is low!")); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
Show All 33 Lines | |||||
} | } | ||||
/** Open an undo file (rev?????.dat) */ | /** Open an undo file (rev?????.dat) */ | ||||
static FILE *OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly) { | static FILE *OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly) { | ||||
return OpenDiskFile(pos, "rev", fReadOnly); | return OpenDiskFile(pos, "rev", fReadOnly); | ||||
} | } | ||||
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix) { | fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix) { | ||||
return GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile); | return GetBlocksDir() / strprintf("%s%05u.dat", prefix, pos.nFile); | ||||
} | } | ||||
CBlockIndex *CChainState::InsertBlockIndex(const uint256 &hash) { | CBlockIndex *CChainState::InsertBlockIndex(const uint256 &hash) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (hash.IsNull()) { | if (hash.IsNull()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,305 Lines • Show Last 20 Lines |