diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -173,12 +173,7 @@ std::unique_ptr pcoinsTip; std::unique_ptr pblocktree; -enum FlushStateMode { - FLUSH_STATE_NONE, - FLUSH_STATE_IF_NEEDED, - FLUSH_STATE_PERIODIC, - FLUSH_STATE_ALWAYS -}; +enum class FlushStateMode { NONE, IF_NEEDED, PERIODIC, ALWAYS }; // See definition for documentation static bool FlushStateToDisk(const CChainParams &chainParams, @@ -760,7 +755,8 @@ // After we've (potentially) uncached entries, ensure our coins cache is // still within its size limits CValidationState stateDummy; - FlushStateToDisk(config.GetChainParams(), stateDummy, FLUSH_STATE_PERIODIC); + FlushStateToDisk(config.GetChainParams(), stateDummy, + FlushStateMode::PERIODIC); return res; } @@ -2012,25 +2008,25 @@ // The cache is large and we're within 10% and 10 MiB of the limit, // but we have time now (not in the middle of a block processing). bool fCacheLarge = - mode == FLUSH_STATE_PERIODIC && + mode == FlushStateMode::PERIODIC && cacheSize > std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024); // The cache is over the limit, we have to write now. bool fCacheCritical = - mode == FLUSH_STATE_IF_NEEDED && cacheSize > nTotalSpace; + mode == FlushStateMode::IF_NEEDED && cacheSize > nTotalSpace; // It's been a while since we wrote the block index to disk. Do this // frequently, so we don't need to redownload after a crash. bool fPeriodicWrite = - mode == FLUSH_STATE_PERIODIC && + mode == FlushStateMode::PERIODIC && nNow > nLastWrite + (int64_t)DATABASE_WRITE_INTERVAL * 1000000; // It's been very long since we flushed the cache. Do this // infrequently, to optimize cache usage. bool fPeriodicFlush = - mode == FLUSH_STATE_PERIODIC && + mode == FlushStateMode::PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000; // Combine all conditions that result in a full cache flush. - fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || + fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune; // Write blocks and block index to disk. if (fDoFullFlush || fPeriodicWrite) { @@ -2096,7 +2092,8 @@ } if (fDoFullFlush || - ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && + ((mode == FlushStateMode::ALWAYS || + mode == FlushStateMode::PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) { // Update best block in wallet (so we can detect restored wallets). @@ -2113,14 +2110,14 @@ void FlushStateToDisk() { CValidationState state; const CChainParams &chainparams = Params(); - FlushStateToDisk(chainparams, state, FLUSH_STATE_ALWAYS); + FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS); } void PruneAndFlush() { CValidationState state; fCheckForPruning = true; const CChainParams &chainparams = Params(); - FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); + FlushStateToDisk(chainparams, state, FlushStateMode::NONE); } /** @@ -2236,7 +2233,7 @@ // Write the chain state to disk, if necessary. if (!FlushStateToDisk(config.GetChainParams(), state, - FLUSH_STATE_IF_NEEDED)) { + FlushStateMode::IF_NEEDED)) { return false; } @@ -2507,7 +2504,7 @@ // Write the chain state to disk, if necessary. if (!FlushStateToDisk(config.GetChainParams(), state, - FLUSH_STATE_IF_NEEDED)) { + FlushStateMode::IF_NEEDED)) { return false; } @@ -2936,7 +2933,7 @@ CheckBlockIndex(params.GetConsensus()); // Write changes periodically to disk, after relay. - if (!FlushStateToDisk(params, state, FLUSH_STATE_PERIODIC)) { + if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { return false; } @@ -3988,7 +3985,7 @@ if (fCheckForPruning) { // we just allocated more disk space for block files. - FlushStateToDisk(config.GetChainParams(), state, FLUSH_STATE_NONE); + FlushStateToDisk(config.GetChainParams(), state, FlushStateMode::NONE); } return true; @@ -4177,7 +4174,8 @@ void PruneBlockFilesManual(int nManualPruneHeight) { CValidationState state; const CChainParams &chainparams = Params(); - FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE, nManualPruneHeight); + FlushStateToDisk(chainparams, state, FlushStateMode::NONE, + nManualPruneHeight); } /** @@ -4804,7 +4802,7 @@ } // Occasionally flush state to disk. - if (!FlushStateToDisk(params, state, FLUSH_STATE_PERIODIC)) { + if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { return false; } } @@ -4831,7 +4829,7 @@ // FlushStateToDisk can possibly read chainActive. Be conservative // and skip it here, we're about to -reindex-chainstate anyway, so // it'll get called a bunch real soon. - if (!FlushStateToDisk(params, state, FLUSH_STATE_ALWAYS)) { + if (!FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) { return false; } }