diff options
author | Andrew Chow <github@achow101.com> | 2023-11-30 14:17:29 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-11-30 14:28:46 -0500 |
commit | 498994b6f55d04a7940f832e7fbd17e5acdaff15 (patch) | |
tree | 10451ec061f4456b88d0c3a2d0d3c8c4c3db2b44 /src/node | |
parent | ffb021612b8f581cbbaffacc80922d1bc5683706 (diff) | |
parent | 5b3ea5fa2e7f6dc1c9161ed8b74c9be4bd1e92dd (diff) | |
download | bitcoin-498994b6f55d04a7940f832e7fbd17e5acdaff15.tar.xz |
Merge bitcoin/bitcoin#26762: bugfix: Make `CCheckQueue` RAII-styled (attempt 2)
5b3ea5fa2e7f6dc1c9161ed8b74c9be4bd1e92dd refactor: Move `{MAX,DEFAULT}_SCRIPTCHECK_THREADS` constants (Hennadii Stepanov)
6e17b3168072ab77ed7170ab81327c017877133a refactor: Make `CCheckQueue` non-copyable and non-movable explicitly (Hennadii Stepanov)
8111e74653dc5c93cb510672d99048c3f741d8dc refactor: Drop unneeded declaration (Hennadii Stepanov)
9cf89f7a5b81197e38f58b24be0793b28fe41477 refactor: Make `CCheckQueue` constructor start worker threads (Hennadii Stepanov)
d03eaacbcfb276fb638db1b423113ff43bd7ec41 Make `CCheckQueue` destructor stop worker threads (Hennadii Stepanov)
be4ff3060b7b43b496dfb5a2c02b114b2b717106 Move global `scriptcheckqueue` into `ChainstateManager` class (Hennadii Stepanov)
Pull request description:
This PR:
- makes `CCheckQueue` RAII-styled
- gets rid of the global `scriptcheckqueue`
- fixes https://github.com/bitcoin/bitcoin/issues/25448
The previous attempt was in https://github.com/bitcoin/bitcoin/pull/18731.
ACKs for top commit:
martinus:
ACK 5b3ea5fa2e7
achow101:
ACK 5b3ea5fa2e7f6dc1c9161ed8b74c9be4bd1e92dd
TheCharlatan:
ACK 5b3ea5fa2e7f6dc1c9161ed8b74c9be4bd1e92dd
Tree-SHA512: 45cca846e7ed107e3930149f0b616ddbaf2648d6cde381f815331b861b5d67ab39e154883ae174b8abb1dae485bc904318c50c51e5d6b46923d89de51c5eadb0
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/chainstatemanager_args.cpp | 14 | ||||
-rw-r--r-- | src/node/chainstatemanager_args.h | 5 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp index 87d9238c18..1cc126cb05 100644 --- a/src/node/chainstatemanager_args.cpp +++ b/src/node/chainstatemanager_args.cpp @@ -6,7 +6,8 @@ #include <arith_uint256.h> #include <common/args.h> -#include <kernel/chainstatemanager_opts.h> +#include <common/system.h> +#include <logging.h> #include <node/coins_view_args.h> #include <node/database_args.h> #include <tinyformat.h> @@ -16,6 +17,7 @@ #include <util/translation.h> #include <validation.h> +#include <algorithm> #include <chrono> #include <string> @@ -41,6 +43,16 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage ReadDatabaseArgs(args, opts.coins_db); ReadCoinsViewArgs(args, opts.coins_view); + int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS); + if (script_threads <= 0) { + // -par=0 means autodetect (number of cores - 1 script threads) + // -par=-n means "leave n cores free" (number of cores - n - 1 script threads) + script_threads += GetNumCores(); + } + // Subtract 1 because the main thread counts towards the par threads. + 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); + return {}; } } // namespace node diff --git a/src/node/chainstatemanager_args.h b/src/node/chainstatemanager_args.h index 701515953e..b2cdba68b8 100644 --- a/src/node/chainstatemanager_args.h +++ b/src/node/chainstatemanager_args.h @@ -10,6 +10,11 @@ class ArgsManager; +/** Maximum number of dedicated script-checking threads allowed */ +static constexpr int MAX_SCRIPTCHECK_THREADS{15}; +/** -par default (number of script-checking threads, 0 = auto) */ +static constexpr int DEFAULT_SCRIPTCHECK_THREADS{0}; + namespace node { [[nodiscard]] util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts); } // namespace node |