Changeset View
Changeset View
Standalone View
Standalone View
src/script/sigcache.cpp
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | size_t nMaxCacheSize = | ||||
MAX_MAX_SIG_CACHE_SIZE) * | MAX_MAX_SIG_CACHE_SIZE) * | ||||
(size_t(1) << 20); | (size_t(1) << 20); | ||||
size_t nElems = signatureCache.setup_bytes(nMaxCacheSize); | size_t nElems = signatureCache.setup_bytes(nMaxCacheSize); | ||||
LogPrintf("Using %zu MiB out of %zu requested for signature cache, able to " | LogPrintf("Using %zu MiB out of %zu requested for signature cache, able to " | ||||
"store %zu elements\n", | "store %zu elements\n", | ||||
(nElems * sizeof(uint256)) >> 20, nMaxCacheSize >> 20, nElems); | (nElems * sizeof(uint256)) >> 20, nMaxCacheSize >> 20, nElems); | ||||
} | } | ||||
bool CachingTransactionSignatureChecker::VerifySignature( | template <typename F> | ||||
const std::vector<uint8_t> &vchSig, const CPubKey &pubkey, | bool RunMemoizedCheck(const std::vector<uint8_t> &vchSig, const CPubKey &pubkey, | ||||
const uint256 &sighash) const { | const uint256 &sighash, bool store, const F &fun) { | ||||
deadalnix: Store is a very bad name. This controls whether thing are stored in the cache, for sure, but… | |||||
markblundebergAuthorUnsubmitted Done Inline ActionsDo you have a suggestion? markblundeberg: Do you have a suggestion? | |||||
uint256 entry; | uint256 entry; | ||||
signatureCache.ComputeEntry(entry, sighash, vchSig, pubkey); | signatureCache.ComputeEntry(entry, sighash, vchSig, pubkey); | ||||
if (signatureCache.Get(entry, !store)) { | if (signatureCache.Get(entry, !store)) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!TransactionSignatureChecker::VerifySignature(vchSig, pubkey, | if (!fun()) { | ||||
sighash)) { | |||||
return false; | return false; | ||||
} | } | ||||
if (store) { | if (store) { | ||||
signatureCache.Set(entry); | signatureCache.Set(entry); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CachingTransactionSignatureChecker::IsCached( | |||||
const std::vector<uint8_t> &vchSig, const CPubKey &pubkey, | |||||
const uint256 &sighash) const { | |||||
return RunMemoizedCheck(vchSig, pubkey, sighash, true, | |||||
[] { return false; }); | |||||
} | |||||
bool CachingTransactionSignatureChecker::VerifySignature( | |||||
const std::vector<uint8_t> &vchSig, const CPubKey &pubkey, | |||||
const uint256 &sighash) const { | |||||
return RunMemoizedCheck(vchSig, pubkey, sighash, store, [&] { | |||||
return TransactionSignatureChecker::VerifySignature(vchSig, pubkey, | |||||
sighash); | |||||
}); | |||||
} |
Store is a very bad name. This controls whether thing are stored in the cache, for sure, but this is also to mark an entry as to be cleaned or not. This needs a better name.