From 606a7ab862470413ced400aa68a94fd37c8ad3d3 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Sat, 18 May 2024 11:18:44 +0200 Subject: [PATCH] kernel: De-globalize signature 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. Use this opportunity to make SignatureCache RAII styled Co-authored-by: Ryan Ofsky --- src/Makefile.am | 3 --- src/bitcoin-chainstate.cpp | 7 ----- src/init.cpp | 9 +------ src/kernel/chainstatemanager_opts.h | 1 + src/kernel/validation_cache_sizes.h | 19 ------------- src/node/chainstatemanager_args.cpp | 1 + src/node/validation_cache_args.cpp | 33 ----------------------- src/node/validation_cache_args.h | 17 ------------ src/script/sigcache.cpp | 41 ++++++++--------------------- src/script/sigcache.h | 23 ++++++++-------- src/test/fuzz/script_sigcache.cpp | 5 +++- src/test/script_p2sh_tests.cpp | 3 ++- src/test/script_tests.cpp | 9 ++++--- src/test/transaction_tests.cpp | 5 +++- src/test/util/setup_common.cpp | 8 ------ src/validation.cpp | 11 ++++---- src/validation.h | 12 ++++++--- 17 files changed, 54 insertions(+), 153 deletions(-) delete mode 100644 src/kernel/validation_cache_sizes.h delete mode 100644 src/node/validation_cache_args.cpp delete mode 100644 src/node/validation_cache_args.h diff --git a/src/Makefile.am b/src/Makefile.am index 52d4aae8939..c1c9b17c9d4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -195,7 +195,6 @@ BITCOIN_CORE_H = \ kernel/mempool_removal_reason.h \ kernel/messagestartchars.h \ kernel/notifications_interface.h \ - kernel/validation_cache_sizes.h \ kernel/warning.h \ key.h \ key_io.h \ @@ -240,7 +239,6 @@ BITCOIN_CORE_H = \ node/txreconciliation.h \ node/types.h \ node/utxo_snapshot.h \ - node/validation_cache_args.h \ node/warnings.h \ noui.h \ outputtype.h \ @@ -445,7 +443,6 @@ libbitcoin_node_a_SOURCES = \ node/transaction.cpp \ node/txreconciliation.cpp \ node/utxo_snapshot.cpp \ - node/validation_cache_args.cpp \ node/warnings.cpp \ noui.cpp \ policy/v3_policy.cpp \ diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index d11d793d218..98af162b4d4 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -63,12 +62,6 @@ int main(int argc, char* argv[]) // properly assert(kernel::SanityChecks(kernel_context)); - // Necessary for CheckInputScripts (eventually called by ProcessNewBlock), - // which will try the script cache first and fall back to actually - // performing the check with the signature cache. - kernel::ValidationCacheSizes validation_cache_sizes{}; - Assert(InitSignatureCache(validation_cache_sizes.signature_cache_bytes)); - ValidationSignals validation_signals{std::make_unique()}; class KernelNotifications : public kernel::Notifications diff --git a/src/init.cpp b/src/init.cpp index 5accc63f375..c368c9c3dc6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -54,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -119,7 +117,6 @@ using common::AmountErrMsg; using common::InvalidPortErrMsg; using common::ResolveErrMsg; -using kernel::ValidationCacheSizes; using node::ApplyArgsManOptions; using node::BlockManager; @@ -619,7 +616,7 @@ void SetupServerArgs(ArgsManager& argsman) argsman.AddArg("-test=