Bitcoin ABC  0.22.12
P2P Digital Currency
scriptcache.h
Go to the documentation of this file.
1 // Copyright (c) 2017 - The Bitcoin Developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_SCRIPT_SCRIPTCACHE_H
6 #define BITCOIN_SCRIPT_SCRIPTCACHE_H
7 
8 #include <array>
9 #include <cstdint>
10 
11 class CTransaction;
12 
23  std::array<uint8_t, 28> data;
24 
25 public:
26  ScriptCacheKey() = default;
27  ScriptCacheKey(const ScriptCacheKey &rhs) = default;
28  ScriptCacheKey(const CTransaction &tx, uint32_t flags);
29 
30  bool operator==(const ScriptCacheKey &rhs) const {
31  return rhs.data == data;
32  }
33 
34  friend class ScriptCacheHasher;
35 };
36 
37 // DoS prevention: limit cache size to 32MB (over 1000000 entries on 64-bit
38 // systems). Due to how we count cache size, actual memory usage is slightly
39 // more (~32.25 MB)
40 static const unsigned int DEFAULT_MAX_SCRIPT_CACHE_SIZE = 32;
41 // Maximum sig cache size allowed
42 static const int64_t MAX_MAX_SCRIPT_CACHE_SIZE = 16384;
43 
46 
51 bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut);
52 
56 void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks);
57 
58 #endif // BITCOIN_SCRIPT_SCRIPTCACHE_H
static const int64_t MAX_MAX_SCRIPT_CACHE_SIZE
Definition: scriptcache.h:42
std::array< uint8_t, 28 > data
Definition: scriptcache.h:23
bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut)
Check if a given key is in the cache, and if so, return its values.
The script cache is a map using a key/value element, that caches the success of executing a specific ...
Definition: scriptcache.h:22
ScriptCacheKey()=default
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: scriptcache.cpp:76
bool operator==(const ScriptCacheKey &rhs) const
Definition: scriptcache.h:30
void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks)
Add an entry in the cache.
static const unsigned int DEFAULT_MAX_SCRIPT_CACHE_SIZE
Definition: scriptcache.h:40
int flags
Definition: bitcoin-tx.cpp:529
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:211