kernel: Add interrupt function to C header
What changed, and why it matters
This commit adds a new public API function that lets outside callers request an interruption of long-running Bitcoin Core kernel operations such as block processing or reindexing. It is a straightforward feature addition with no security-relevant bug fix or behavior change to existing code.
No security action required. Review as normal feature/API addition.
Security signals we found
No vulnerability pattern present
No memory-safety bug introduced
No change to validation consensus rules
No change to network or wallet behavior
New API only exposes pre-existing interrupt mechanism
Evidence from the diff
The change exposes btck_context_interrupt() in the kernel C API and a matching C++ wrapper Context::interrupt(). The implementation invokes the existing interrupt flag on the copied context. A test is added to verify the call succeeds. No existing logic is modified; only new API surface is introduced.
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hsrc/kernel/bitcoinkernel_wrapper.hsrc/test/kernel/test_kernel.cppInspect captured patch +22 / −0
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index 0c5d811d..1c146df0 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -676,6 +676,11 @@ btck_Context* btck_context_copy(const btck_Context* context)
return btck_Context::copy(context);
}
+int btck_context_interrupt(btck_Context* context)
+{
+ return (*btck_Context::get(context)->m_interrupt)() ? 0 : -1;
+}
+
void btck_context_destroy(btck_Context* context)
{
delete context;
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index 651c54c4..8d7b2898 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -704,6 +704,16 @@ BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_cr
BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_copy(
const btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
+/**
+ * @brief Interrupt can be used to halt long-running validation functions like
+ * when reindexing, importing or processing blocks.
+ *
+ * @param[in] context Non-null.
+ * @return 0 if the interrupt was successful, non-zero otherwise.
+ */
+BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_interrupt(
+ btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
+
/**
* Destroy the context.
*/
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index ff16f5bc..4c378d3a 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -651,6 +651,11 @@ public:
Context()
: Handle{btck_context_create(ContextOptions{}.get())} {}
+
+ bool interrupt()
+ {
+ return btck_context_interrupt(get()) == 0;
+ }
};
class ChainstateManagerOptions : public UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index 128f3f49..cfe3b2d2 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -634,6 +634,8 @@ BOOST_AUTO_TEST_CASE(btck_chainman_in_memory_tests)
BOOST_CHECK(std::filesystem::exists(in_memory_test_directory.m_directory / "blocks"));
BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "blocks" / "index"));
BOOST_CHECK(!std::filesystem::exists(in_memory_test_directory.m_directory / "chainstate"));
+
+ BOOST_CHECK(context.interrupt());
}
BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
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.