18#include <shared_mutex>
28class CSignatureCache {
36 std::shared_mutex cs_sigcache;
49 const std::vector<uint8_t> &
vchSig,
51 CSHA256 hasher = m_salted_hasher;
58 bool Get(
const uint256 &entry,
const bool erase) {
59 std::shared_lock<std::shared_mutex> lock(cs_sigcache);
60 return setValid.contains(entry, erase);
63 void Set(
const uint256 &entry) {
64 std::unique_lock<std::shared_mutex> lock(cs_sigcache);
65 setValid.insert(entry);
67 std::optional<std::pair<uint32_t, size_t>> setup_bytes(
size_t n) {
68 return setValid.setup_bytes(n);
92 LogPrintf(
"Using %zu MiB out of %zu MiB requested for signature cache, "
93 "able to store %zu elements\n",
119 [] {
return false; });
virtual bool VerifySignature(const std::vector< uint8_t > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
An encapsulated public key.
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
const uint8_t * data() const
A hasher class for SHA-256.
CSHA256 & Write(const uint8_t *data, size_t len)
void Finalize(uint8_t hash[OUTPUT_SIZE])
bool VerifySignature(const std::vector< uint8_t > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const override
bool IsCached(const std::vector< uint8_t > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
cache implements a cache with properties similar to a cuckoo-set.
We're hashing a nonce into the entries themselves, so we don't need extra blinding in the set hash co...
uint256 GetRandHash() noexcept
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
bool RunMemoizedCheck(const std::vector< uint8_t > &vchSig, const CPubKey &pubkey, const uint256 &sighash, bool storeOrErase, const F &fun)
bool InitSignatureCache(size_t max_size_bytes)