Bitcoin ABC  0.26.3
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 #include <sync.h>
12 
13 // Actually declared in validation.cpp; can't include because of circular
14 // dependency.
15 extern RecursiveMutex cs_main;
16 
17 class CTransaction;
18 
29  std::array<uint8_t, 28> data;
30 
31 public:
32  ScriptCacheKey() = default;
33  ScriptCacheKey(const ScriptCacheKey &rhs) = default;
34  ScriptCacheKey(const CTransaction &tx, uint32_t flags);
35 
36  ScriptCacheKey &operator=(const ScriptCacheKey &rhs) = default;
37 
38  bool operator==(const ScriptCacheKey &rhs) const {
39  return rhs.data == data;
40  }
41 
42  friend class ScriptCacheHasher;
43 };
44 
45 // DoS prevention: limit cache size to 32MB (over 1000000 entries on 64-bit
46 // systems). Due to how we count cache size, actual memory usage is slightly
47 // more (~32.25 MB)
48 static const unsigned int DEFAULT_MAX_SCRIPT_CACHE_SIZE = 32;
49 // Maximum sig cache size allowed
50 static const int64_t MAX_MAX_SCRIPT_CACHE_SIZE = 16384;
51 
54 
59 bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut)
61 
67 
68 #endif // BITCOIN_SCRIPT_SCRIPTCACHE_H
int flags
Definition: bitcoin-tx.cpp:538
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
The script cache is a map using a key/value element, that caches the success of executing a specific ...
Definition: scriptcache.h:28
std::array< uint8_t, 28 > data
Definition: scriptcache.h:29
ScriptCacheKey & operator=(const ScriptCacheKey &rhs)=default
ScriptCacheKey(const ScriptCacheKey &rhs)=default
bool operator==(const ScriptCacheKey &rhs) const
Definition: scriptcache.h:38
ScriptCacheKey()=default
unsigned int nSigChecks
static const int64_t MAX_MAX_SCRIPT_CACHE_SIZE
Definition: scriptcache.h:50
static const unsigned int DEFAULT_MAX_SCRIPT_CACHE_SIZE
Definition: scriptcache.h:48
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: scriptcache.cpp:76
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:113
void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Add an entry in the cache.
bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check if a given key is in the cache, and if so, return its values.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56