14 #include <boost/thread.hpp> 15 #include <boost/unordered_set.hpp> 23 class CSignatureCacheHasher
27 return key.GetCheapHash();
41 typedef boost::unordered_set<uint256, CSignatureCacheHasher> map_type;
43 boost::shared_mutex cs_sigcache;
53 ComputeEntry(
uint256& entry,
const uint256 &hash,
const std::vector<unsigned char>& vchSig,
const CPubKey& pubkey)
61 boost::shared_lock<boost::shared_mutex> lock(cs_sigcache);
62 return setValid.count(entry);
65 void Erase(
const uint256& entry)
67 boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
68 setValid.erase(entry);
74 if (nMaxCacheSize <= 0)
return;
76 boost::unique_lock<boost::shared_mutex> lock(cs_sigcache);
79 map_type::size_type s =
GetRand(setValid.bucket_count());
80 map_type::local_iterator it = setValid.begin(s);
81 if (it != setValid.end(s)) {
86 setValid.insert(entry);
94 static CSignatureCache signatureCache;
97 signatureCache.ComputeEntry(entry, sighash, vchSig, pubkey);
99 if (signatureCache.Get(entry)) {
101 signatureCache.Erase(entry);
110 signatureCache.Set(entry);
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE
static size_t DynamicUsage(const int8_t &v)
CSHA256 & Write(const unsigned char *data, size_t len)
virtual bool VerifySignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
void GetRandBytes(unsigned char *buf, int num)
bool VerifySignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
std::string GetArg(const std::string &strArg, const std::string &strDefault)
uint64_t GetRand(uint64_t nMax)