@@ -173,15 +173,7 @@ std::unique_ptr<CCoinsViewDB> pcoinsdbview;
173173std::unique_ptr<CCoinsViewCache> pcoinsTip;
174174std::unique_ptr<CBlockTreeDB> pblocktree;
175175
176- enum class FlushStateMode {
177- NONE,
178- IF_NEEDED,
179- PERIODIC,
180- ALWAYS
181- };
182-
183176// See definition for documentation
184- static bool FlushStateToDisk (const CChainParams& chainParams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight=0 );
185177static void FindFilesToPruneManual (std::set<int >& setFilesToPrune, int nManualPruneHeight);
186178static void FindFilesToPrune (std::set<int >& setFilesToPrune, uint64_t nPruneAfterHeight);
187179bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr );
@@ -854,7 +846,7 @@ static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPo
854846 }
855847 // After we've (potentially) uncached entries, ensure our coins cache is still within its size limits
856848 CValidationState stateDummy;
857- FlushStateToDisk (chainparams, stateDummy, FlushStateMode::PERIODIC);
849+ ::ChainstateActive (). FlushStateToDisk(chainparams, stateDummy, FlushStateMode::PERIODIC);
858850 return res;
859851}
860852
@@ -1951,16 +1943,12 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
19511943 return true ;
19521944}
19531945
1954- /* *
1955- * Update the on-disk chain state.
1956- * The caches and indexes are flushed depending on the mode we're called with
1957- * if they're too large, if it's been a while since the last write,
1958- * or always and in all cases if we're in prune mode and are deleting files.
1959- *
1960- * If FlushStateMode::NONE is used, then FlushStateToDisk(...) won't do anything
1961- * besides checking if we need to prune.
1962- */
1963- bool static FlushStateToDisk (const CChainParams& chainparams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight) {
1946+ bool CChainState::FlushStateToDisk (
1947+ const CChainParams& chainparams,
1948+ CValidationState &state,
1949+ FlushStateMode mode,
1950+ int nManualPruneHeight)
1951+ {
19641952 int64_t nMempoolUsage = mempool.DynamicMemoryUsage ();
19651953 LOCK (cs_main);
19661954 static int64_t nLastWrite = 0 ;
@@ -2058,27 +2046,28 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
20582046 }
20592047 if (full_flush_completed) {
20602048 // Update best block in wallet (so we can detect restored wallets).
2061- GetMainSignals ().ChainStateFlushed (:: ChainActive () .GetLocator ());
2049+ GetMainSignals ().ChainStateFlushed (m_chain .GetLocator ());
20622050 }
20632051 } catch (const std::runtime_error& e) {
20642052 return AbortNode (state, std::string (" System error while flushing: " ) + e.what ());
20652053 }
20662054 return true ;
20672055}
20682056
2069- void FlushStateToDisk () {
2057+ void CChainState::ForceFlushStateToDisk () {
20702058 CValidationState state;
20712059 const CChainParams& chainparams = Params ();
2072- if (!FlushStateToDisk (chainparams, state, FlushStateMode::ALWAYS)) {
2060+ if (!this -> FlushStateToDisk (chainparams, state, FlushStateMode::ALWAYS)) {
20732061 LogPrintf (" %s: failed to flush state (%s)\n " , __func__, FormatStateMessage (state));
20742062 }
20752063}
20762064
2077- void PruneAndFlush () {
2065+ void CChainState:: PruneAndFlush () {
20782066 CValidationState state;
20792067 fCheckForPruning = true ;
20802068 const CChainParams& chainparams = Params ();
2081- if (!FlushStateToDisk (chainparams, state, FlushStateMode::NONE)) {
2069+
2070+ if (!this ->FlushStateToDisk (chainparams, state, FlushStateMode::NONE)) {
20822071 LogPrintf (" %s: failed to flush state (%s)\n " , __func__, FormatStateMessage (state));
20832072 }
20842073}
@@ -3587,7 +3576,8 @@ void PruneBlockFilesManual(int nManualPruneHeight)
35873576{
35883577 CValidationState state;
35893578 const CChainParams& chainparams = Params ();
3590- if (!FlushStateToDisk (chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) {
3579+ if (!::ChainstateActive ().FlushStateToDisk (
3580+ chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) {
35913581 LogPrintf (" %s: failed to flush state (%s)\n " , __func__, FormatStateMessage (state));
35923582 }
35933583}
@@ -4183,7 +4173,7 @@ bool RewindBlockIndex(const CChainParams& params) {
41834173 // and skip it here, we're about to -reindex-chainstate anyway, so
41844174 // it'll get called a bunch real soon.
41854175 CValidationState state;
4186- if (!FlushStateToDisk (params, state, FlushStateMode::ALWAYS)) {
4176+ if (!:: ChainstateActive (). FlushStateToDisk (params, state, FlushStateMode::ALWAYS)) {
41874177 LogPrintf (" RewindBlockIndex: unable to flush state to disk (%s)\n " , FormatStateMessage (state));
41884178 return false ;
41894179 }
0 commit comments