Merge #9777: Handle unusual maxsigcachesize gracefully

55c403b Ensure `-maxsigcachesize` is in valid range (John Newbery)
This commit is contained in:
Wladimir J. van der Laan 2017-02-17 09:05:39 +01:00
commit 8dee822177
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
2 changed files with 5 additions and 2 deletions

View File

@ -93,8 +93,9 @@ static CSignatureCache signatureCache;
// To be called once in AppInit2/TestingSetup to initialize the signatureCache
void InitSignatureCache()
{
size_t nMaxCacheSize = GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20);
if (nMaxCacheSize <= 0) return;
// nMaxCacheSize is unsigned. If -maxsigcachesize is set to zero,
// setup_bytes creates the minimum possible cache (2 elements).
size_t nMaxCacheSize = std::min(std::max((int64_t)0, GetArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_SIZE)), MAX_MAX_SIG_CACHE_SIZE) * ((size_t) 1 << 20);
size_t nElems = signatureCache.setup_bytes(nMaxCacheSize);
LogPrintf("Using %zu MiB out of %zu requested for signature cache, able to store %zu elements\n",
(nElems*sizeof(uint256)) >>20, nMaxCacheSize>>20, nElems);

View File

@ -14,6 +14,8 @@
// 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;
// Maximum sig cache size allowed
static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384;
class CPubKey;