aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2024-07-08 11:37:14 -0400
committerRyan Ofsky <ryan@ofsky.org>2024-07-08 12:14:12 -0400
commit94d56b9def44bfa5e002ef2c666e5961b1deacdc (patch)
treea52211d3e1b08898710c779fdc4749a097eac3db /src/node
parent1c11089c7f11d3fe6e6dcf856c1330a1721048cf (diff)
parent606a7ab862470413ced400aa68a94fd37c8ad3d3 (diff)
downloadbitcoin-94d56b9def44bfa5e002ef2c666e5961b1deacdc.tar.xz
Merge bitcoin/bitcoin#30141: kernel: De-globalize validation caches
606a7ab862470413ced400aa68a94fd37c8ad3d3 kernel: De-globalize signature cache (TheCharlatan) 66d74bfc45ae0f743084475ac3bbfb4355bb6ec2 Expose CSignatureCache class in header (TheCharlatan) 021d38822c0e6a1b9497bcb20401c5c37e1bb84d kernel: De-globalize script execution cache hasher (TheCharlatan) 13a3661aba95b54b822c99ecbb695b14a22536d2 kernel: De-globalize script execution cache (TheCharlatan) ab14d1d6a4a8ef5fe5013150e6c5ebcb5f5e4ea9 validation: Don't error if maxsigcachesize exceeds uint32::max (TheCharlatan) Pull request description: The validation caches are currently setup independently from where the rest of the validation code is initialized. This makes their ownership semantics unclear. There is also no clear enforcement on when and in what order they need to be initialized. The caches are always initialized in the `BasicTestingSetup` although a number of tests don't actually need them. Solve this by moving the caches from global scope into the `ChainstateManager` class. This simplifies the usage of the kernel library by no longer requiring manual setup of the caches prior to using the `ChainstateManager`. Tests that need to access the caches can instantiate them independently. --- This pull request is part of the [libbitcoinkernel project](https://github.com/bitcoin/bitcoin/issues/27587). ACKs for top commit: stickies-v: re-ACK 606a7ab862470413ced400aa68a94fd37c8ad3d3 glozow: reACK 606a7ab ryanofsky: Code review ACK 606a7ab862470413ced400aa68a94fd37c8ad3d3. Just small formatting, include, and static_assert changes since last review. Tree-SHA512: e7f3ee41406e3b233832bb67dc3a63c4203b5367e5daeed383df9cb590f227fcc62eae31311029c077d5e81b273a37a88a364db3dee2efe91bb3b9c9ddc8a42e
Diffstat (limited to 'src/node')
-rw-r--r--src/node/chainstatemanager_args.cpp10
-rw-r--r--src/node/validation_cache_args.cpp34
-rw-r--r--src/node/validation_cache_args.h17
3 files changed, 10 insertions, 51 deletions
diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp
index bc4a815a3e..39b5f3ad3e 100644
--- a/src/node/chainstatemanager_args.cpp
+++ b/src/node/chainstatemanager_args.cpp
@@ -56,6 +56,16 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
opts.worker_threads_num = std::clamp(script_threads - 1, 0, MAX_SCRIPTCHECK_THREADS);
LogPrintf("Script verification uses %d additional threads\n", opts.worker_threads_num);
+ if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
+ // 1. When supplied with a max_size of 0, both the signature cache and
+ // script execution cache create the minimum possible cache (2
+ // elements). Therefore, we can use 0 as a floor here.
+ // 2. Multiply first, divide after to avoid integer truncation.
+ size_t clamped_size_each = std::max<int64_t>(*max_size, 0) * (1 << 20) / 2;
+ opts.script_execution_cache_bytes = clamped_size_each;
+ opts.signature_cache_bytes = clamped_size_each;
+ }
+
return {};
}
} // namespace node
diff --git a/src/node/validation_cache_args.cpp b/src/node/validation_cache_args.cpp
deleted file mode 100644
index ddf24f798d..0000000000
--- a/src/node/validation_cache_args.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2022 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include <node/validation_cache_args.h>
-
-#include <kernel/validation_cache_sizes.h>
-
-#include <common/args.h>
-
-#include <algorithm>
-#include <cstddef>
-#include <cstdint>
-#include <memory>
-#include <optional>
-
-using kernel::ValidationCacheSizes;
-
-namespace node {
-void ApplyArgsManOptions(const ArgsManager& argsman, ValidationCacheSizes& cache_sizes)
-{
- if (auto max_size = argsman.GetIntArg("-maxsigcachesize")) {
- // 1. When supplied with a max_size of 0, both InitSignatureCache and
- // InitScriptExecutionCache create the minimum possible cache (2
- // elements). Therefore, we can use 0 as a floor here.
- // 2. Multiply first, divide after to avoid integer truncation.
- size_t clamped_size_each = std::max<int64_t>(*max_size, 0) * (1 << 20) / 2;
- cache_sizes = {
- .signature_cache_bytes = clamped_size_each,
- .script_execution_cache_bytes = clamped_size_each,
- };
- }
-}
-} // namespace node
diff --git a/src/node/validation_cache_args.h b/src/node/validation_cache_args.h
deleted file mode 100644
index f447c13b49..0000000000
--- a/src/node/validation_cache_args.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2022 The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef BITCOIN_NODE_VALIDATION_CACHE_ARGS_H
-#define BITCOIN_NODE_VALIDATION_CACHE_ARGS_H
-
-class ArgsManager;
-namespace kernel {
-struct ValidationCacheSizes;
-};
-
-namespace node {
-void ApplyArgsManOptions(const ArgsManager& argsman, kernel::ValidationCacheSizes& cache_sizes);
-} // namespace node
-
-#endif // BITCOIN_NODE_VALIDATION_CACHE_ARGS_H