From e5ecee8d2d17cf92f47ca500f39bf50e5dd3e48d Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sat, 12 Dec 2020 21:11:43 +0000 Subject: [PATCH] reduce cache sizes so that default maxsigcache size is same as Bitcoin Bitcoin allocates 32M for signature caching by default, split between a signature cache and a script validity cache (see Core #10192). Since 0.14 we have added an additional 32M for rangeproof caching *and* an additional 32M for surjectionproof caching. These cache entries cost a bit over 32 bytes, so these are room for a million entries....or 4Gb of rangeproofs and 300M of surjection proofs. Presumably we did not intend to triple memory usage relative to Core to deal with some champagne problem in which our mempool is overfilled ten times with pure rangeproofs. So put the total default cache size back to 32M. This should have no performance hit under realistic circumstances and should reduce CI OOM failures. On my system we now use 50M rather than 110M during the fedpeg test; we still use 18M that Core does not by having three additional global secp contexts (one in blind.cpp, one in pegins.cpp, one in confidential_validation.cpp) but we can settle that in a future commit. --- src/script/sigcache.cpp | 12 ++++++------ src/validation.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 87487c248e..18a4befd80 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -115,9 +115,9 @@ void InitSignatureCache() { // 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.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 2), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); + size_t nMaxCacheSize = std::min(std::max((int64_t)0, gArgs.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 4), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); size_t nElems = signatureCache.setup_bytes(nMaxCacheSize); - LogPrintf("Using %zu MiB out of %zu/2 requested for signature cache, able to store %zu elements\n", + LogPrintf("Using %zu MiB out of %zu/4 requested for signature cache, able to store %zu elements\n", (nElems*sizeof(uint256)) >>20, (nMaxCacheSize*2)>>20, nElems); } @@ -152,9 +152,9 @@ void InitRangeproofCache() { // 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.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE)), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); + size_t nMaxCacheSize = std::min(std::max((int64_t)0, gArgs.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 4), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); size_t nElems = rangeProofCache.setup_bytes(nMaxCacheSize); - LogPrintf("Using %zu MiB out of %zu requested for rangeproof cache, able to store %zu elements\n", + LogPrintf("Using %zu MiB out of %zu/4 requested for rangeproof cache, able to store %zu elements\n", (nElems*sizeof(uint256)) >>20, nMaxCacheSize>>20, nElems); } @@ -163,9 +163,9 @@ void InitSurjectionproofCache() { // 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.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE)), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); + size_t nMaxCacheSize = std::min(std::max((int64_t)0, gArgs.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 4), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); size_t nElems = surjectionProofCache.setup_bytes(nMaxCacheSize); - LogPrintf("Using %zu MiB out of %zu requested for surjectionproof cache, able to store %zu elements\n", + LogPrintf("Using %zu MiB out of %zu/4 requested for surjectionproof cache, able to store %zu elements\n", (nElems*sizeof(uint256)) >>20, nMaxCacheSize>>20, nElems); } diff --git a/src/validation.cpp b/src/validation.cpp index 5b4841244c..da086153dd 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1580,9 +1580,9 @@ void 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::min(std::max((int64_t)0, gArgs.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 2), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); + size_t nMaxCacheSize = std::min(std::max((int64_t)0, gArgs.GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 4), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); size_t nElems = g_scriptExecutionCache.setup_bytes(nMaxCacheSize); - LogPrintf("Using %zu MiB out of %zu/2 requested for script execution cache, able to store %zu elements\n", + LogPrintf("Using %zu MiB out of %zu/4 requested for script execution cache, able to store %zu elements\n", (nElems*sizeof(uint256)) >>20, (nMaxCacheSize*2)>>20, nElems); }