aboutsummaryrefslogtreecommitdiff
path: root/src/script/sigcache.h
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-06-30 23:47:41 -0400
committerCarl Dong <contact@carldong.me>2022-08-03 12:03:27 -0400
commit41c5201a90bbc2893333e334e8945759ef24e7dd (patch)
tree3c8e26fa4b9769b7a2fa4fa75dd059c84d89fad8 /src/script/sigcache.h
parent82d3058539f54ebad745e2b02b61df01aa832a54 (diff)
downloadbitcoin-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/script/sigcache.h')
-rw-r--r--src/script/sigcache.h9
1 files changed, 5 insertions, 4 deletions
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