Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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;
32
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
The basic transaction that is broadcasted on the network and contained in blocks.
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
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
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.
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(...)