kernel: Add chainstate manager option for setting worker threads
What changed, and why it matters
This commit adds a new configuration option to the Bitcoin Core kernel library that lets callers choose how many worker threads are used during blockchain validation. It is a straightforward feature addition with no security-relevant behavior changes visible in the diff.
No security action required. Review as a normal API/feature change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch exposes a setter (btck_chainstate_manager_options_set_worker_threads_num) and a C++ wrapper method (SetWorkerThreads) for the existing ChainstateManagerOptions.worker_threads_num field. It also adds a unit-test call setting the value to 4. The value is documented to be clamped internally between 0 and 15, and the underlying field already existed; this commit only wires it through the public kernel API.
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hsrc/kernel/bitcoinkernel_wrapper.hsrc/test/kernel/test_kernel.cppInspect captured patch +24 / −0
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index 445ccca9..be0f9808 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -689,6 +689,12 @@ btck_ChainstateManagerOptions* btck_chainstate_manager_options_create(const btck
}
}
+void btck_chainstate_manager_options_set_worker_threads_num(btck_ChainstateManagerOptions* opts, int worker_threads)
+{
+ LOCK(btck_ChainstateManagerOptions::get(opts).m_mutex);
+ btck_ChainstateManagerOptions::get(opts).m_chainman_options.worker_threads_num = worker_threads;
+}
+
void btck_chainstate_manager_options_destroy(btck_ChainstateManagerOptions* options)
{
delete options;
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index 59094aef..63cad6ad 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -729,6 +729,18 @@ BITCOINKERNEL_API btck_ChainstateManagerOptions* BITCOINKERNEL_WARN_UNUSED_RESUL
const char* blocks_directory,
size_t blocks_directory_len) BITCOINKERNEL_ARG_NONNULL(1, 2);
+/**
+ * @brief Set the number of available worker threads used during validation.
+ *
+ * @param[in] chainstate_manager_options Non-null, options to be set.
+ * @param[in] worker_threads The number of worker threads that should be spawned in the thread pool
+ * used for validation. When set to 0 no parallel verification is done.
+ * The value range is clamped internally between 0 and 15.
+ */
+BITCOINKERNEL_API void btck_chainstate_manager_options_set_worker_threads_num(
+ btck_ChainstateManagerOptions* chainstate_manager_options,
+ int worker_threads) BITCOINKERNEL_ARG_NONNULL(1);
+
/**
* Destroy the chainstate manager options.
*/
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index 7d5c3063..bdd71916 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -628,6 +628,11 @@ public:
: UniqueHandle{btck_chainstate_manager_options_create(context.get(), data_dir.c_str(), data_dir.length(), blocks_dir.c_str(), blocks_dir.length())}
{
}
+
+ void SetWorkerThreads(int worker_threads)
+ {
+ btck_chainstate_manager_options_set_worker_threads_num(get(), worker_threads);
+ }
};
class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_destroy>
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index bc00e85c..4b2dc5dc 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -502,5 +502,6 @@ BOOST_AUTO_TEST_CASE(btck_chainman_tests)
auto context{create_context(notifications, ChainType::MAINNET)};
ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
+ chainman_opts.SetWorkerThreads(4);
ChainMan chainman{context, chainman_opts};
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.