14#include <validation.h>
40 "ScriptCacheElement should be 32 bytes");
44 template <u
int8_t hash_select>
46 static_assert(hash_select < 8,
"only has 8 hashes available.");
48 const auto &d = k.
data;
50 static_assert(
sizeof(d) == 28,
51 "modify the following if key size changes");
54 static_assert(
sizeof(u) == 4 &&
sizeof(d[0]) == 1,
"basic assumptions");
55 if (hash_select < 7) {
56 std::memcpy(&u, d.data() + 4 * hash_select, 4);
62 arr[0] = d[3] ^ d[7] ^ d[11] ^ d[15];
63 arr[1] = d[6] ^ d[10] ^ d[14] ^ d[18];
64 arr[2] = d[9] ^ d[13] ^ d[17] ^ d[21];
65 arr[3] = d[12] ^ d[16] ^ d[20] ^ d[24];
66 std::memcpy(&u, arr, 4);
90 const auto [num_elems, approx_size_bytes] = *setup_results;
91 LogPrintf(
"Using %zu MiB out of %zu MiB requested for script execution "
92 "cache, able to store %zu elements\n",
93 approx_size_bytes >> 20, max_size_bytes >> 20, num_elems);
98 std::array<uint8_t, 32> hash;
105 std::copy(hash.begin(), hash.begin() +
data.size(),
data.begin());
A hasher class for SHA-256.
CSHA256 & Write(const uint8_t *data, size_t len)
void Finalize(uint8_t hash[OUTPUT_SIZE])
The basic transaction that is broadcasted on the network and contained in blocks.
const TxHash GetHash() const
cache implements a cache with properties similar to a cuckoo-set.
uint32_t operator()(const ScriptCacheKey &k) const
The script cache is a map using a key/value element, that caches the success of executing a specific ...
std::array< uint8_t, 28 > data
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
uint256 GetRandHash() noexcept
static CSHA256 g_scriptExecutionCacheHasher
static CuckooCache::cache< ScriptCacheElement, ScriptCacheHasher > g_scriptExecutionCache
bool InitScriptExecutionCache(size_t max_size_bytes)
Initializes the script-execution cache.
void AddKeyInScriptCache(ScriptCacheKey key, int nSigChecks)
Add an entry in the cache.
bool IsKeyInScriptCache(ScriptCacheKey key, bool erase, int &nSigChecksOut)
Check if a given key is in the cache, and if so, return its values.
In future if many more values are added, it should be considered to expand the element size to 64 byt...
const KeyType & getKey() const
ScriptCacheElement(const KeyType &keyIn, int nSigChecksIn)
ScriptCacheElement()=default