@@ -135,7 +135,6 @@ bool fPruneMode = false;
135135bool fRequireStandard = true ;
136136bool fCheckBlockIndex = false ;
137137bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
138- size_t nCoinCacheUsage = 5000 * 300 ;
139138uint64_t nPruneTarget = 0 ;
140139int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
141140
@@ -1279,9 +1278,10 @@ void CChainState::InitCoinsDB(
12791278 leveldb_name, cache_size_bytes, in_memory, should_wipe);
12801279}
12811280
1282- void CChainState::InitCoinsCache ()
1281+ void CChainState::InitCoinsCache (size_t cache_size_bytes )
12831282{
12841283 assert (m_coins_views != nullptr );
1284+ m_coinstip_cache_size_bytes = cache_size_bytes;
12851285 m_coins_views->InitCache ();
12861286}
12871287
@@ -2228,7 +2228,7 @@ CoinsCacheSizeState CChainState::GetCoinsCacheSizeState(const CTxMemPool& tx_poo
22282228{
22292229 return this ->GetCoinsCacheSizeState (
22302230 tx_pool,
2231- nCoinCacheUsage ,
2231+ m_coinstip_cache_size_bytes ,
22322232 gArgs .GetArg (" -maxmempool" , DEFAULT_MAX_MEMPOOL_SIZE) * 1000000 );
22332233}
22342234
@@ -4300,7 +4300,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
43004300 }
43014301 }
43024302 // check level 3: check for inconsistencies during memory-only disconnect of tip blocks
4303- if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage () + ::ChainstateActive ().CoinsTip ().DynamicMemoryUsage ()) <= nCoinCacheUsage ) {
4303+ if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage () + ::ChainstateActive ().CoinsTip ().DynamicMemoryUsage ()) <= :: ChainstateActive (). m_coinstip_cache_size_bytes ) {
43044304 assert (coins.GetBestBlock () == pindex->GetBlockHash ());
43054305 DisconnectResult res = ::ChainstateActive ().DisconnectBlock (block, pindex, coins);
43064306 if (res == DISCONNECT_FAILED) {
@@ -4965,6 +4965,39 @@ std::string CChainState::ToString()
49654965 tip ? tip->nHeight : -1 , tip ? tip->GetBlockHash ().ToString () : " null" );
49664966}
49674967
4968+ bool CChainState::ResizeCoinsCaches (size_t coinstip_size, size_t coinsdb_size)
4969+ {
4970+ if (coinstip_size == m_coinstip_cache_size_bytes &&
4971+ coinsdb_size == m_coinsdb_cache_size_bytes) {
4972+ // Cache sizes are unchanged, no need to continue.
4973+ return true ;
4974+ }
4975+ size_t old_coinstip_size = m_coinstip_cache_size_bytes;
4976+ m_coinstip_cache_size_bytes = coinstip_size;
4977+ m_coinsdb_cache_size_bytes = coinsdb_size;
4978+ CoinsDB ().ResizeCache (coinsdb_size);
4979+
4980+ LogPrintf (" [%s] resized coinsdb cache to %.1f MiB\n " ,
4981+ this ->ToString (), coinsdb_size * (1.0 / 1024 / 1024 ));
4982+ LogPrintf (" [%s] resized coinstip cache to %.1f MiB\n " ,
4983+ this ->ToString (), coinstip_size * (1.0 / 1024 / 1024 ));
4984+
4985+ BlockValidationState state;
4986+ const CChainParams& chainparams = Params ();
4987+
4988+ bool ret;
4989+
4990+ if (coinstip_size > old_coinstip_size) {
4991+ // Likely no need to flush if cache sizes have grown.
4992+ ret = FlushStateToDisk (chainparams, state, FlushStateMode::IF_NEEDED);
4993+ } else {
4994+ // Otherwise, flush state to disk and deallocate the in-memory coins map.
4995+ ret = FlushStateToDisk (chainparams, state, FlushStateMode::ALWAYS);
4996+ CoinsTip ().ReallocateCache ();
4997+ }
4998+ return ret;
4999+ }
5000+
49685001std::string CBlockFileInfo::ToString () const
49695002{
49705003 return strprintf (" CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)" , nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date (nTimeFirst), FormatISO8601Date (nTimeLast));
0 commit comments