17#include <shared_mutex>
28 const auto [num_elems, approx_size_bytes] =
30 LogPrintf(
"Using %zu MiB out of %zu MiB requested for signature cache, "
31 "able to store %zu elements\n",
32 approx_size_bytes >> 20, max_size_bytes >> 20, num_elems);
36 const std::vector<uint8_t> &vchSig,
41 .
Write(vchSig.data(), vchSig.size())
46 std::shared_lock<std::shared_mutex> lock(
cs_sigcache);
51 std::unique_lock<std::shared_mutex> lock(
cs_sigcache);
57 const std::vector<uint8_t> &vchSig,
const CPubKey &pubkey,
58 const uint256 &sighash,
bool storeOrErase,
const F &fun) {
60 signatureCache.
ComputeEntry(entry, sighash, vchSig, pubkey);
61 if (signatureCache.
Get(entry, !storeOrErase)) {
68 signatureCache.
Set(entry);
74 const std::vector<uint8_t> &vchSig,
const CPubKey &pubkey,
77 [] {
return false; });
81 const std::vector<uint8_t> &vchSig,
const CPubKey &pubkey,
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
SignatureCache & m_signature_cache
std::pair< uint32_t, size_t > setup_bytes(size_t bytes)
setup_bytes is a convenience function which accounts for internal memory usage when deciding how many...
bool contains(const Key &k, const bool erase) const
contains iterates through the hash locations for a given element and checks to see if it is present.
void insert(Element e, bool replace=false)
insert loops at most depth_limit times trying to insert a hash at various locations in the table via ...
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
SignatureCache(size_t max_size_bytes)
void ComputeEntry(uint256 &entry, const uint256 &hash, const std::vector< uint8_t > &vchSig, const CPubKey &pubkey) const
CSHA256 m_salted_hasher
Entries are SHA256(nonce || signature hash || public key || signature):
std::shared_mutex cs_sigcache
bool Get(const uint256 &entry, const bool erase)
void Set(const uint256 &entry)
uint256 GetRandHash() noexcept
bool RunMemoizedCheck(SignatureCache &signatureCache, const std::vector< uint8_t > &vchSig, const CPubKey &pubkey, const uint256 &sighash, bool storeOrErase, const F &fun)