-
Notifications
You must be signed in to change notification settings - Fork 0
Merge bitcoin/bitcoin#25527: [kernel 3c/n] Decouple validation cache initialization from ArgsManager
#1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: backport-0.24-batch-463
Are you sure you want to change the base?
Merge bitcoin/bitcoin#25527: [kernel 3c/n] Decouple validation cache initialization from ArgsManager
#1204
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // 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_KERNEL_VALIDATION_CACHE_SIZES_H | ||
| #define BITCOIN_KERNEL_VALIDATION_CACHE_SIZES_H | ||
|
|
||
| #include <script/sigcache.h> | ||
|
|
||
| #include <cstddef> | ||
| #include <limits> | ||
|
|
||
| namespace kernel { | ||
| struct ValidationCacheSizes { | ||
| size_t signature_cache_bytes{DEFAULT_MAX_SIG_CACHE_BYTES / 2}; | ||
| size_t script_execution_cache_bytes{DEFAULT_MAX_SIG_CACHE_BYTES / 2}; | ||
| }; | ||
| } | ||
|
|
||
| #endif // BITCOIN_KERNEL_VALIDATION_CACHE_SIZES_H |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||||||||||||
| // 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 <script/sigcache.h> | ||||||||||||||||||
|
|
||||||||||||||||||
| #include <util/system.h> | ||||||||||||||||||
|
|
||||||||||||||||||
| #include <algorithm> | ||||||||||||||||||
| #include <cstddef> | ||||||||||||||||||
| #include <cstdint> | ||||||||||||||||||
| #include <memory> | ||||||||||||||||||
| #include <optional> | ||||||||||||||||||
|
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Potentially unused includes. The headers #include <algorithm>
#include <cstddef>
#include <cstdint>
-#include <memory>
-#include <optional>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| using kernel::ValidationCacheSizes; | ||||||||||||||||||
|
|
||||||||||||||||||
| namespace node { | ||||||||||||||||||
| void ApplyArgsManOptions(const ArgsManager& argsman, ValidationCacheSizes& cache_sizes) | ||||||||||||||||||
| { | ||||||||||||||||||
| if (argsman.IsArgSet("-maxsigcachesize")) { | ||||||||||||||||||
| int64_t max_size = argsman.GetIntArg("-maxsigcachesize", DEFAULT_MAX_SIG_CACHE_BYTES >> 20); | ||||||||||||||||||
| // 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 | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial LGTM! New header file correctly declares the Minor style note: Line 11 has a trailing semicolon after the namespace closing brace ( namespace kernel {
struct ValidationCacheSizes;
-};
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
LGTM! The API change properly handles uint32_t overflow and returns useful sizing metadata.
Minor note:
bytes/sizeof(Element)is computed twice (line 368 and 373). This is harmless since the compiler will likely optimize it, but could be simplified by reusingrequested_num_elemsafter the overflow check:📝 Committable suggestion
🤖 Prompt for AI Agents