Bitcoin ABC  0.24.10
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 
65 void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks)
67 
68 #endif // BITCOIN_SCRIPT_SCRIPTCACHE_H
InitScriptExecutionCache
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: scriptcache.cpp:76
MAX_MAX_SCRIPT_CACHE_SIZE
static const int64_t MAX_MAX_SCRIPT_CACHE_SIZE
Definition: scriptcache.h:50
flags
int flags
Definition: bitcoin-tx.cpp:532
sync.h
AnnotatedMixin< std::recursive_mutex >
ScriptCacheKey::data
std::array< uint8_t, 28 > data
Definition: scriptcache.h:29
ScriptCacheHasher
Definition: scriptcache.cpp:42
ScriptCacheKey::operator=
ScriptCacheKey & operator=(const ScriptCacheKey &rhs)=default
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
AddKeyInScriptCache
void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Add an entry in the cache.
Definition: scriptcache.cpp:120
ScriptCacheKey::operator==
bool operator==(const ScriptCacheKey &rhs) const
Definition: scriptcache.h:38
DEFAULT_MAX_SCRIPT_CACHE_SIZE
static const unsigned int DEFAULT_MAX_SCRIPT_CACHE_SIZE
Definition: scriptcache.h:48
ScriptCacheKey::ScriptCacheKey
ScriptCacheKey()=default
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
IsKeyInScriptCache
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.
Definition: scriptcache.cpp:109
cs_main
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:103
ScriptCacheKey
The script cache is a map using a key/value element, that caches the success of executing a specific ...
Definition: scriptcache.h:28