From 08dbc6ef72db48168dc03991f5f838dae42c8dfd Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Thu, 30 Jun 2022 23:10:55 -0400 Subject: 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. --- src/script/sigcache.cpp | 12 ++++++++---- src/script/sigcache.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/script') diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 4e2acc463a..7cee55a431 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -75,7 +75,7 @@ public: std::unique_lock lock(cs_sigcache); setValid.insert(entry); } - uint32_t setup_bytes(size_t n) + std::pair setup_bytes(size_t n) { return setValid.setup_bytes(n); } @@ -92,14 +92,18 @@ static CSignatureCache signatureCache; // To be called once in AppInitMain/BasicTestingSetup to initialize the // signatureCache. -void InitSignatureCache() +bool 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.GetIntArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) / 2), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20); - size_t nElems = signatureCache.setup_bytes(nMaxCacheSize); + + auto setup_results = signatureCache.setup_bytes(nMaxCacheSize); + + 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", - (nElems*sizeof(uint256)) >>20, (nMaxCacheSize*2)>>20, nElems); + approx_size_bytes >> 20, (nMaxCacheSize * 2) >> 20, num_elems); + return true; } bool CachingTransactionSignatureChecker::VerifyECDSASignature(const std::vector& vchSig, const CPubKey& pubkey, const uint256& sighash) const diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 1e21d6f340..edcba2543c 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -33,6 +33,6 @@ public: bool VerifySchnorrSignature(Span sig, const XOnlyPubKey& pubkey, const uint256& sighash) const override; }; -void InitSignatureCache(); +[[nodiscard]] bool InitSignatureCache(); #endif // BITCOIN_SCRIPT_SIGCACHE_H -- cgit v1.2.3