Skip to content

Commit ff873a2

Browse files
committed
Merge bitcoin/bitcoin#31313: refactor: Clamp worker threads in ChainstateManager constructor
8f85d36 refactor: Clamp worker threads in ChainstateManager constructor (TheCharlatan) Pull request description: This ensures the options are applied consistently from contexts where they might not pass through the args manager, such as in some tests, or when used through the kernel library. This is similar to the patch applied in 09ef322, used to make applying the mempool options consistent. --- This is part of the libbitcoinkernel project bitcoin/bitcoin#27587 ACKs for top commit: maflcko: ACK 8f85d36 🛳 achow101: ACK 8f85d36 furszy: Code ACK 8f85d36 stickies-v: ACK 8f85d36 Tree-SHA512: 32d7cc177d6726ee9df62ac9eb43e49ba676f35bfcff47834bd97a1e33f2a9ea7be65d0a8a37be149de04e58c9c500ecef730e498f4e3909042324d3136160e9
2 parents c9a7418 + 8f85d36 commit ff873a2

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

src/checkqueue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_CHECKQUEUE_H
66
#define BITCOIN_CHECKQUEUE_H
77

8+
#include <logging.h>
89
#include <sync.h>
910
#include <tinyformat.h>
1011
#include <util/threadnames.h>
@@ -143,6 +144,7 @@ class CCheckQueue
143144
explicit CCheckQueue(unsigned int batch_size, int worker_threads_num)
144145
: nBatchSize(batch_size)
145146
{
147+
LogInfo("Script verification uses %d additional threads", worker_threads_num);
146148
m_worker_threads.reserve(worker_threads_num);
147149
for (int n = 0; n < worker_threads_num; ++n) {
148150
m_worker_threads.emplace_back([this, n]() {

src/node/chainstatemanager_args.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
6060
script_threads += GetNumCores();
6161
}
6262
// Subtract 1 because the main thread counts towards the par threads.
63-
opts.worker_threads_num = std::clamp(script_threads - 1, 0, MAX_SCRIPTCHECK_THREADS);
64-
LogPrintf("Script verification uses %d additional threads\n", opts.worker_threads_num);
63+
opts.worker_threads_num = script_threads - 1;
6564

6665
if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
6766
// 1. When supplied with a max_size of 0, both the signature cache and

src/node/chainstatemanager_args.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
class ArgsManager;
1212

13-
/** Maximum number of dedicated script-checking threads allowed */
14-
static constexpr int MAX_SCRIPTCHECK_THREADS{15};
1513
/** -par default (number of script-checking threads, 0 = auto) */
1614
static constexpr int DEFAULT_SCRIPTCHECK_THREADS{0};
1715

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6294,7 +6294,7 @@ static ChainstateManager::Options&& Flatten(ChainstateManager::Options&& opts)
62946294
}
62956295

62966296
ChainstateManager::ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options)
6297-
: m_script_check_queue{/*batch_size=*/128, options.worker_threads_num},
6297+
: m_script_check_queue{/*batch_size=*/128, std::clamp(options.worker_threads_num, 0, MAX_SCRIPTCHECK_THREADS)},
62986298
m_interrupt{interrupt},
62996299
m_options{Flatten(std::move(options))},
63006300
m_blockman{interrupt, std::move(blockman_options)},

src/validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ static constexpr int DEFAULT_CHECKLEVEL{3};
7878
// Setting the target to >= 550 MiB will make it likely we can respect the target.
7979
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
8080

81+
/** Maximum number of dedicated script-checking threads allowed */
82+
static constexpr int MAX_SCRIPTCHECK_THREADS{15};
83+
8184
/** Current sync state passed to tip changed callbacks. */
8285
enum class SynchronizationState {
8386
INIT_REINDEX,

0 commit comments

Comments
 (0)