|
|
|
@ -18,6 +18,8 @@
|
|
|
|
|
#include <flatfile.h>
|
|
|
|
|
#include <hash.h>
|
|
|
|
|
#include <index/txindex.h>
|
|
|
|
|
#include <logging.h>
|
|
|
|
|
#include <logging/timer.h>
|
|
|
|
|
#include <policy/fees.h>
|
|
|
|
|
#include <policy/policy.h>
|
|
|
|
|
#include <policy/settings.h>
|
|
|
|
@ -2023,6 +2025,10 @@ bool CChainState::FlushStateToDisk(
|
|
|
|
|
static int64_t nLastFlush = 0;
|
|
|
|
|
std::set<int> setFilesToPrune;
|
|
|
|
|
bool full_flush_completed = false;
|
|
|
|
|
|
|
|
|
|
const size_t coins_count = CoinsTip().GetCacheSize();
|
|
|
|
|
const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
{
|
|
|
|
|
bool fFlushForPrune = false;
|
|
|
|
@ -2030,8 +2036,12 @@ bool CChainState::FlushStateToDisk(
|
|
|
|
|
LOCK(cs_LastBlockFile);
|
|
|
|
|
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) {
|
|
|
|
|
if (nManualPruneHeight > 0) {
|
|
|
|
|
LOG_TIME_MILLIS("find files to prune (manual)", BCLog::BENCH);
|
|
|
|
|
|
|
|
|
|
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight);
|
|
|
|
|
} else {
|
|
|
|
|
LOG_TIME_MILLIS("find files to prune", BCLog::BENCH);
|
|
|
|
|
|
|
|
|
|
FindFilesToPrune(setFilesToPrune, chainparams.PruneAfterHeight());
|
|
|
|
|
fCheckForPruning = false;
|
|
|
|
|
}
|
|
|
|
@ -2070,10 +2080,17 @@ bool CChainState::FlushStateToDisk(
|
|
|
|
|
if (!CheckDiskSpace(GetBlocksDir())) {
|
|
|
|
|
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!").translated, CClientUIInterface::MSG_NOPREFIX);
|
|
|
|
|
}
|
|
|
|
|
// First make sure all block and undo data is flushed to disk.
|
|
|
|
|
FlushBlockFile();
|
|
|
|
|
{
|
|
|
|
|
LOG_TIME_MILLIS("write block and undo data to disk", BCLog::BENCH);
|
|
|
|
|
|
|
|
|
|
// First make sure all block and undo data is flushed to disk.
|
|
|
|
|
FlushBlockFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then update all block file information (which may refer to block and undo files).
|
|
|
|
|
{
|
|
|
|
|
LOG_TIME_MILLIS("write block index to disk", BCLog::BENCH);
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<int, const CBlockFileInfo*> > vFiles;
|
|
|
|
|
vFiles.reserve(setDirtyFileInfo.size());
|
|
|
|
|
for (std::set<int>::iterator it = setDirtyFileInfo.begin(); it != setDirtyFileInfo.end(); ) {
|
|
|
|
@ -2091,12 +2108,18 @@ bool CChainState::FlushStateToDisk(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Finally remove any pruned files
|
|
|
|
|
if (fFlushForPrune)
|
|
|
|
|
if (fFlushForPrune) {
|
|
|
|
|
LOG_TIME_MILLIS("unlink pruned files", BCLog::BENCH);
|
|
|
|
|
|
|
|
|
|
UnlinkPrunedFiles(setFilesToPrune);
|
|
|
|
|
}
|
|
|
|
|
nLastWrite = nNow;
|
|
|
|
|
}
|
|
|
|
|
// Flush best chain related state. This can only be done if the blocks / block index write was also done.
|
|
|
|
|
if (fDoFullFlush && !CoinsTip().GetBestBlock().IsNull()) {
|
|
|
|
|
LOG_TIME_SECONDS(strprintf("write coins cache to disk (%d coins, %.2fkB)",
|
|
|
|
|
coins_count, coins_mem_usage / 1000));
|
|
|
|
|
|
|
|
|
|
// Typical Coin structures on disk are around 48 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
|
|
|
|
|