|
|
@ -1863,13 +1863,17 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight) { |
|
|
|
bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight) { |
|
|
|
int64_t nMempoolUsage = mempool.DynamicMemoryUsage(); |
|
|
|
int64_t nMempoolUsage = mempool.DynamicMemoryUsage(); |
|
|
|
LOCK2(cs_main, cs_LastBlockFile); |
|
|
|
LOCK(cs_main); |
|
|
|
static int64_t nLastWrite = 0; |
|
|
|
static int64_t nLastWrite = 0; |
|
|
|
static int64_t nLastFlush = 0; |
|
|
|
static int64_t nLastFlush = 0; |
|
|
|
static int64_t nLastSetChain = 0; |
|
|
|
static int64_t nLastSetChain = 0; |
|
|
|
std::set<int> setFilesToPrune; |
|
|
|
std::set<int> setFilesToPrune; |
|
|
|
bool fFlushForPrune = false; |
|
|
|
bool fFlushForPrune = false; |
|
|
|
|
|
|
|
bool fDoFullFlush = false; |
|
|
|
|
|
|
|
int64_t nNow = 0; |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_LastBlockFile); |
|
|
|
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) { |
|
|
|
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) { |
|
|
|
if (nManualPruneHeight > 0) { |
|
|
|
if (nManualPruneHeight > 0) { |
|
|
|
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight); |
|
|
|
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight); |
|
|
@ -1885,7 +1889,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState & |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
int64_t nNow = GetTimeMicros(); |
|
|
|
nNow = GetTimeMicros(); |
|
|
|
// Avoid writing/flushing immediately after startup.
|
|
|
|
// Avoid writing/flushing immediately after startup.
|
|
|
|
if (nLastWrite == 0) { |
|
|
|
if (nLastWrite == 0) { |
|
|
|
nLastWrite = nNow; |
|
|
|
nLastWrite = nNow; |
|
|
@ -1908,7 +1912,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState & |
|
|
|
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
|
|
|
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
|
|
|
bool fPeriodicFlush = mode == FLUSH_STATE_PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000; |
|
|
|
bool fPeriodicFlush = mode == FLUSH_STATE_PERIODIC && 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.
|
|
|
|
bool fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune; |
|
|
|
fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || 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
|
|
|
@ -1953,6 +1957,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState & |
|
|
|
return AbortNode(state, "Failed to write to coin database"); |
|
|
|
return AbortNode(state, "Failed to write to coin database"); |
|
|
|
nLastFlush = nNow; |
|
|
|
nLastFlush = nNow; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (fDoFullFlush || ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) { |
|
|
|
if (fDoFullFlush || ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) { |
|
|
|
// Update best block in wallet (so we can detect restored wallets).
|
|
|
|
// Update best block in wallet (so we can detect restored wallets).
|
|
|
|
GetMainSignals().SetBestChain(chainActive.GetLocator()); |
|
|
|
GetMainSignals().SetBestChain(chainActive.GetLocator()); |
|
|
|