diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/sigcache.cpp | 8 | ||||
-rw-r--r-- | src/script/sigcache.h | 9 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 507754ad7d..8e6971d3f3 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -93,18 +93,18 @@ static CSignatureCache signatureCache; // To be called once in AppInitMain/BasicTestingSetup to initialize the // signatureCache. -bool InitSignatureCache() +bool InitSignatureCache(int64_t max_size_bytes) { // 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 = signatureCache.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 signature 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 signature cache, able to store %zu elements\n", + approx_size_bytes >> 20, max_size_bytes >> 20, num_elems); return true; } diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 0e3f900acf..4c1cad38a7 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -10,12 +10,13 @@ #include <span.h> #include <util/hasher.h> +#include <optional> #include <vector> -// DoS prevention: limit cache size to 32MB (over 1000000 entries on 64-bit +// DoS prevention: limit cache size to 32MiB (over 1000000 entries on 64-bit // systems). Due to how we count cache size, actual memory usage is slightly -// more (~32.25 MB) -static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE = 32; +// more (~32.25 MiB) +static constexpr size_t DEFAULT_MAX_SIG_CACHE_BYTES{32 << 20}; class CPubKey; @@ -31,6 +32,6 @@ public: bool VerifySchnorrSignature(Span<const unsigned char> sig, const XOnlyPubKey& pubkey, const uint256& sighash) const override; }; -[[nodiscard]] bool InitSignatureCache(); +[[nodiscard]] bool InitSignatureCache(int64_t max_size_bytes); #endif // BITCOIN_SCRIPT_SIGCACHE_H |