aboutsummaryrefslogtreecommitdiff
path: root/src/validation.h
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2024-05-17 23:33:25 +0200
committerTheCharlatan <seb.kung@gmail.com>2024-07-04 22:39:37 +0200
commit13a3661aba95b54b822c99ecbb695b14a22536d2 (patch)
tree560db9184bf7eeb72994f64a3bc7f3f1a616dc4b /src/validation.h
parentab14d1d6a4a8ef5fe5013150e6c5ebcb5f5e4ea9 (diff)
downloadbitcoin-13a3661aba95b54b822c99ecbb695b14a22536d2.tar.xz
kernel: De-globalize script execution cache
Move its ownership to the ChainstateManager class. Next to simplifying usage of the kernel library by no longer requiring manual setup of the cache prior to using validation code, it also slims down the amount of memory allocated by BasicTestingSetup.
Diffstat (limited to 'src/validation.h')
-rw-r--r--src/validation.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/validation.h b/src/validation.h
index ab7891539a..efe7661b5f 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -10,9 +10,10 @@
#include <attributes.h>
#include <chain.h>
#include <checkqueue.h>
-#include <kernel/chain.h>
#include <consensus/amount.h>
+#include <cuckoocache.h>
#include <deploymentstatus.h>
+#include <kernel/chain.h>
#include <kernel/chainparams.h>
#include <kernel/chainstatemanager_opts.h>
#include <kernel/cs_main.h> // IWYU pragma: export
@@ -360,8 +361,19 @@ static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
-/** Initializes the script-execution cache */
-[[nodiscard]] bool InitScriptExecutionCache(size_t max_size_bytes);
+/**
+ * Convenience class for initializing and passing the script execution cache.
+ */
+class ValidationCache
+{
+public:
+ CuckooCache::cache<uint256, SignatureCacheHasher> m_script_execution_cache;
+
+ ValidationCache(size_t script_execution_cache_bytes);
+
+ ValidationCache(const ValidationCache&) = delete;
+ ValidationCache& operator=(const ValidationCache&) = delete;
+};
/** Functions for validating blocks and updating the block tree */
@@ -796,7 +808,6 @@ private:
friend ChainstateManager;
};
-
enum class SnapshotCompletionResult {
SUCCESS,
SKIPPED,
@@ -970,6 +981,8 @@ public:
//! chainstate to avoid duplicating block metadata.
node::BlockManager m_blockman;
+ ValidationCache m_validation_cache;
+
/**
* Whether initial block download has ended and IsInitialBlockDownload
* should return false from now on.