@@ -173,15 +173,7 @@ std::unique_ptr<CCoinsViewDB> pcoinsdbview;
173
173
std::unique_ptr<CCoinsViewCache> pcoinsTip;
174
174
std::unique_ptr<CBlockTreeDB> pblocktree;
175
175
176
- enum class FlushStateMode {
177
- NONE,
178
- IF_NEEDED,
179
- PERIODIC,
180
- ALWAYS
181
- };
182
-
183
176
// See definition for documentation
184
- static bool FlushStateToDisk (const CChainParams& chainParams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight=0 );
185
177
static void FindFilesToPruneManual (std::set<int >& setFilesToPrune, int nManualPruneHeight);
186
178
static void FindFilesToPrune (std::set<int >& setFilesToPrune, uint64_t nPruneAfterHeight);
187
179
bool 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
854
846
}
855
847
// After we've (potentially) uncached entries, ensure our coins cache is still within its size limits
856
848
CValidationState stateDummy;
857
- FlushStateToDisk (chainparams, stateDummy, FlushStateMode::PERIODIC);
849
+ ::ChainstateActive (). FlushStateToDisk(chainparams, stateDummy, FlushStateMode::PERIODIC);
858
850
return res;
859
851
}
860
852
@@ -1951,16 +1943,12 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
1951
1943
return true ;
1952
1944
}
1953
1945
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
+ {
1964
1952
int64_t nMempoolUsage = mempool.DynamicMemoryUsage ();
1965
1953
LOCK (cs_main);
1966
1954
static int64_t nLastWrite = 0 ;
@@ -2058,27 +2046,28 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
2058
2046
}
2059
2047
if (full_flush_completed) {
2060
2048
// Update best block in wallet (so we can detect restored wallets).
2061
- GetMainSignals ().ChainStateFlushed (:: ChainActive () .GetLocator ());
2049
+ GetMainSignals ().ChainStateFlushed (m_chain .GetLocator ());
2062
2050
}
2063
2051
} catch (const std::runtime_error& e) {
2064
2052
return AbortNode (state, std::string (" System error while flushing: " ) + e.what ());
2065
2053
}
2066
2054
return true ;
2067
2055
}
2068
2056
2069
- void FlushStateToDisk () {
2057
+ void CChainState::ForceFlushStateToDisk () {
2070
2058
CValidationState state;
2071
2059
const CChainParams& chainparams = Params ();
2072
- if (!FlushStateToDisk (chainparams, state, FlushStateMode::ALWAYS)) {
2060
+ if (!this -> FlushStateToDisk (chainparams, state, FlushStateMode::ALWAYS)) {
2073
2061
LogPrintf (" %s: failed to flush state (%s)\n " , __func__, FormatStateMessage (state));
2074
2062
}
2075
2063
}
2076
2064
2077
- void PruneAndFlush () {
2065
+ void CChainState:: PruneAndFlush () {
2078
2066
CValidationState state;
2079
2067
fCheckForPruning = true ;
2080
2068
const CChainParams& chainparams = Params ();
2081
- if (!FlushStateToDisk (chainparams, state, FlushStateMode::NONE)) {
2069
+
2070
+ if (!this ->FlushStateToDisk (chainparams, state, FlushStateMode::NONE)) {
2082
2071
LogPrintf (" %s: failed to flush state (%s)\n " , __func__, FormatStateMessage (state));
2083
2072
}
2084
2073
}
@@ -3587,7 +3576,8 @@ void PruneBlockFilesManual(int nManualPruneHeight)
3587
3576
{
3588
3577
CValidationState state;
3589
3578
const CChainParams& chainparams = Params ();
3590
- if (!FlushStateToDisk (chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) {
3579
+ if (!::ChainstateActive ().FlushStateToDisk (
3580
+ chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) {
3591
3581
LogPrintf (" %s: failed to flush state (%s)\n " , __func__, FormatStateMessage (state));
3592
3582
}
3593
3583
}
@@ -4183,7 +4173,7 @@ bool RewindBlockIndex(const CChainParams& params) {
4183
4173
// and skip it here, we're about to -reindex-chainstate anyway, so
4184
4174
// it'll get called a bunch real soon.
4185
4175
CValidationState state;
4186
- if (!FlushStateToDisk (params, state, FlushStateMode::ALWAYS)) {
4176
+ if (!:: ChainstateActive (). FlushStateToDisk (params, state, FlushStateMode::ALWAYS)) {
4187
4177
LogPrintf (" RewindBlockIndex: unable to flush state to disk (%s)\n " , FormatStateMessage (state));
4188
4178
return false ;
4189
4179
}
0 commit comments