diff options
author | Carl Dong <contact@carldong.me> | 2022-06-30 23:47:41 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-08-03 12:03:27 -0400 |
commit | 41c5201a90bbc2893333e334e8945759ef24e7dd (patch) | |
tree | 3c8e26fa4b9769b7a2fa4fa75dd059c84d89fad8 /src/validation.cpp | |
parent | 82d3058539f54ebad745e2b02b61df01aa832a54 (diff) | |
download | bitcoin-41c5201a90bbc2893333e334e8945759ef24e7dd.tar.xz |
validationcaches: Add and use ValidationCacheSizes
Also:
- Make DEFAULT_MAX_SIG_CACHE_SIZE into constexpr
DEFAULT_MAX_SIG_CACHE_BYTES to utilize the compile-time integer
arithmetic overflow checking available to constexpr.
- Fix comment (MiB instead of MB) for DEFAULT_MAX_SIG_CACHE_BYTES.
- Pass in max_size_bytes parameter to InitS*Cache(), modify log line to
no longer allude to maxsigcachesize being split evenly between the two
validation caches.
- Fix possible integer truncation and add a comment.
[META] I've kept the integer types as int64_t in order to not introduce
unintended behaviour changes, in the next commit we will make
them size_t.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 73a6e46cc4..7a03adf558 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1656,7 +1656,8 @@ bool CScriptCheck::operator()() { static CuckooCache::cache<uint256, SignatureCacheHasher> g_scriptExecutionCache; static CSHA256 g_scriptExecutionCacheHasher; -bool InitScriptExecutionCache() { +bool InitScriptExecutionCache(int64_t max_size_bytes) +{ // Setup the salted hasher uint256 nonce = GetRandHash(); // We want the nonce to be 64 bytes long to force the hasher to process @@ -1666,14 +1667,14 @@ bool InitScriptExecutionCache() { g_scriptExecutionCacheHasher.Write(nonce.begin(), 32); // nMaxCacheSize is unsigned. If -maxsigcachesize is set to zero, // setup_bytes creates the minimum possible cache (2 elements). - size_t nMaxCacheSize = std::max((int64_t)0, gArgs.GetIntArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 2) * ((size_t) 1 << 20); + size_t nMaxCacheSize = std::max<int64_t>(max_size_bytes, 0); auto setup_results = g_scriptExecutionCache.setup_bytes(nMaxCacheSize); if (!setup_results) return false; 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", - approx_size_bytes >> 20, (nMaxCacheSize * 2) >> 20, num_elems); + LogPrintf("Using %zu MiB out of %zu MiB requested for script execution cache, able to store %zu elements\n", + approx_size_bytes >> 20, max_size_bytes >> 20, num_elems); return true; } |