diff options
author | Carl Dong <contact@carldong.me> | 2022-06-30 23:10:55 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-08-03 12:02:31 -0400 |
commit | 08dbc6ef72db48168dc03991f5f838dae42c8dfd (patch) | |
tree | f78f5551eea5874f068a05f3bbab1a9563f01493 /src/validation.cpp | |
parent | 0dbce4b1034b53d19b88af332385a006098b6d48 (diff) |
cuckoocache: Return approximate memory size
Returning the approximate total size eliminates the need for
InitS*Cache() to do nElems*sizeof(uint256). The cuckoocache has a better
idea of this information.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index d018d185e9..d0c84ba317 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1656,7 +1656,7 @@ bool CScriptCheck::operator()() { static CuckooCache::cache<uint256, SignatureCacheHasher> g_scriptExecutionCache; static CSHA256 g_scriptExecutionCacheHasher; -void InitScriptExecutionCache() { +bool InitScriptExecutionCache() { // Setup the salted hasher uint256 nonce = GetRandHash(); // We want the nonce to be 64 bytes long to force the hasher to process @@ -1667,9 +1667,13 @@ void InitScriptExecutionCache() { // nMaxCacheSize is unsigned. If -maxsigcachesize is set to zero, // setup_bytes creates the minimum possible cache (2 elements). size_t nMaxCacheSize = std::min(std::max((int64_t)0, gArgs.GetIntArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 2), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); - size_t nElems = g_scriptExecutionCache.setup_bytes(nMaxCacheSize); + + auto setup_results = g_scriptExecutionCache.setup_bytes(nMaxCacheSize); + + const auto [num_elems, approx_size_bytes] = setup_results; LogPrintf("Using %zu MiB out of %zu/2 requested for script execution cache, able to store %zu elements\n", - (nElems*sizeof(uint256)) >>20, (nMaxCacheSize*2)>>20, nElems); + approx_size_bytes >> 20, (nMaxCacheSize * 2) >> 20, num_elems); + return true; } /** |