Bitcoin ABC 0.30.5
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 <kernel/cs_main.h>
12#include <sync.h>
13
14class CTransaction;
15
26 std::array<uint8_t, 28> data;
27
28public:
29 ScriptCacheKey() = default;
30 ScriptCacheKey(const ScriptCacheKey &rhs) = default;
31 ScriptCacheKey(const CTransaction &tx, uint32_t flags);
32
33 ScriptCacheKey &operator=(const ScriptCacheKey &rhs) = default;
34
35 bool operator==(const ScriptCacheKey &rhs) const {
36 return rhs.data == data;
37 }
38
39 friend class ScriptCacheHasher;
40};
41
42// DoS prevention: limit cache size to 32MiB (over 1000000 entries on 64-bit
43// systems). Due to how we count cache size, actual memory usage is slightly
44// more (~32.25 MiB)
45static constexpr size_t DEFAULT_MAX_SCRIPT_CACHE_BYTES{32 << 20};
46
48[[nodiscard]] bool InitScriptExecutionCache(size_t max_size_bytes);
49
54bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut)
56
62
63#endif // BITCOIN_SCRIPT_SCRIPTCACHE_H
int flags
Definition: bitcoin-tx.cpp:541
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
The script cache is a map using a key/value element, that caches the success of executing a specific ...
Definition: scriptcache.h:25
ScriptCacheKey & operator=(const ScriptCacheKey &rhs)=default
std::array< uint8_t, 28 > data
Definition: scriptcache.h:26
ScriptCacheKey(const ScriptCacheKey &rhs)=default
bool operator==(const ScriptCacheKey &rhs) const
Definition: scriptcache.h:35
ScriptCacheKey()=default
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
unsigned int nSigChecks
static constexpr size_t DEFAULT_MAX_SCRIPT_CACHE_BYTES
Definition: scriptcache.h:45
bool InitScriptExecutionCache(size_t max_size_bytes)
Initializes the script-execution cache.
Definition: scriptcache.cpp:76
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