Skip to content

Commit 40743f2

Browse files
committed
Squashed 'libbitcoinkernel-sys/bitcoin/' changes from 6090df267dfe..9e203b460d8a
9e203b460d8a kernel: Add pure kernel bitcoin-chainstate a568bf9a494d kernel: Add functions to get the block hash from a block 237b97dd542b kernel: Add block index utility functions to C header f6b3f264e2f6 kernel: Add function to read block undo data from disk to C header 90875aedcd64 kernel: Add functions to read block from disk to C header 90b9adb287b6 kernel: Add function for copying block data to C header d17e5dd695f4 kernel: Add functions for the block validation state to C header f61407f19aaf kernel: Add validation interface to C header 6d2b74ee03fe kernel: Add interrupt function to C header 1385c03b10c5 kernel: Add import blocks function to C header 229d696f3826 kernel: Add chainstate load options for in-memory dbs in C header d239f5504ca2 kernel: Add options for reindexing in C header d351759979f4 kernel: Add block validation to C header 4ebfbf84491f Kernel: Add chainstate loading to kernel C header b15df6bb21f1 kernel: Add chainstate manager option for setting worker threads e2cbb3265c44 kernel: Add chainstate manager object to C header 2818646db5f8 kernel: Add notifications context option to C header eb91f6c35dd5 kerenl: Add chain params context option to C header a1045172f381 kernel: Add kernel library context object 373f260d97ec kernel: Add logging to kernel library C header 20f5156bd517 kernel: Introduce initial kernel C header API REVERT: 6090df267dfe kernel: Add pure kernel bitcoin-chainstate REVERT: 29e3b874303b kernel: Add functions to get the block hash from a block REVERT: 97d83063cb66 kernel: Add block index utility functions to C header REVERT: 76ead0878a32 kernel: Add function to read block undo data from disk to C header REVERT: 94c215c42127 kernel: Add functions to read block from disk to C header REVERT: aff05fcbe62d kernel: Add function for copying block data to C header REVERT: a379fbe15eb7 kernel: Add functions for the block validation state to C header REVERT: 81db16652130 kernel: Add validation interface to C header REVERT: 0ee7a5f58a6c kernel: Add interrupt function to C header REVERT: f68b3dbf9192 kernel: Add import blocks function to C header REVERT: 503aae9afc5c kernel: Add chainstate load options for in-memory dbs in C header REVERT: fa1335fd8099 kernel: Add options for reindexing in C header REVERT: 0eb020f9c82e kernel: Add block validation to C header REVERT: 5f4717296745 Kernel: Add chainstate loading to kernel C header REVERT: 90949cbb09d9 kernel: Add chainstate manager option for setting worker threads REVERT: a2021b517c66 kernel: Add chainstate manager object to C header REVERT: 428ea46909b3 kernel: Add notifications context option to C header REVERT: b1f5d450323b kerenl: Add chain params context option to C header REVERT: 7bb4b412db0c kernel: Add kernel library context object REVERT: e4b63d7f5d95 kernel: Add logging to kernel library C header REVERT: 47bb56b243e7 kernel: Introduce initial kernel C header API git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 9e203b460d8ab1d92949ab8714a9265c343a5eee
1 parent 15319cf commit 40743f2

File tree

4 files changed

+25
-68
lines changed

4 files changed

+25
-68
lines changed

src/kernel/bitcoinkernel.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,6 @@ const CChainParams* cast_const_chain_params(const kernel_ChainParameters* chain_
301301
return reinterpret_cast<const CChainParams*>(chain_params);
302302
}
303303

304-
const KernelNotifications* cast_const_notifications(const kernel_Notifications* notifications)
305-
{
306-
assert(notifications);
307-
return reinterpret_cast<const KernelNotifications*>(notifications);
308-
}
309-
310304
Context* cast_context(kernel_Context* context)
311305
{
312306
assert(context);
@@ -607,18 +601,6 @@ void kernel_chain_parameters_destroy(const kernel_ChainParameters* chain_paramet
607601
}
608602
}
609603

610-
kernel_Notifications* kernel_notifications_create(kernel_NotificationInterfaceCallbacks callbacks)
611-
{
612-
return reinterpret_cast<kernel_Notifications*>(new KernelNotifications{callbacks});
613-
}
614-
615-
void kernel_notifications_destroy(kernel_Notifications* notifications)
616-
{
617-
if (notifications) {
618-
delete cast_const_notifications(notifications);
619-
}
620-
}
621-
622604
kernel_ContextOptions* kernel_context_options_create()
623605
{
624606
return reinterpret_cast<kernel_ContextOptions*>(new ContextOptions{});
@@ -632,12 +614,11 @@ void kernel_context_options_set_chainparams(kernel_ContextOptions* options_, con
632614
options->m_chainparams = std::make_unique<const CChainParams>(*chain_params);
633615
}
634616

635-
void kernel_context_options_set_notifications(kernel_ContextOptions* options_, const kernel_Notifications* notifications_)
617+
void kernel_context_options_set_notifications(kernel_ContextOptions* options_, kernel_NotificationInterfaceCallbacks notifications)
636618
{
637619
auto options{cast_context_options(options_)};
638-
auto notifications{reinterpret_cast<const KernelNotifications*>(notifications_)};
639620
// Copy the notifications, so the caller can free it again
640-
options->m_notifications = std::make_unique<const KernelNotifications>(*notifications);
621+
options->m_notifications = std::make_unique<const KernelNotifications>(notifications);
641622
}
642623

643624
void kernel_context_options_set_validation_interface(kernel_ContextOptions* options_, kernel_ValidationInterfaceCallbacks vi_cbs)

src/kernel/bitcoinkernel.h

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ extern "C" {
4141
#endif // __cplusplus
4242

4343
/**
44-
* ------ Context ------
44+
* @page remarks Remarks
45+
*
46+
* @section context Context
4547
*
4648
* The library provides a built-in static constant kernel context. This static
4749
* context offers only limited functionality. It detects and self-checks the
@@ -53,7 +55,7 @@ extern "C" {
5355
* The user should create their own context for passing it to state-rich validation
5456
* functions and holding callbacks for kernel events.
5557
*
56-
* ------ Error handling ------
58+
* @section error Error handling
5759
*
5860
* Functions communicate an error through their return types, usually returning
5961
* a nullptr, or false if an error is encountered. Additionally, verification
@@ -68,7 +70,7 @@ extern "C" {
6870
* to halt and tear down the existing kernel objects. Remediating the error may
6971
* require system intervention by the user.
7072
*
71-
* ------ Pointer and argument conventions ------
73+
* @section pointer Pointer and argument conventions
7274
*
7375
* The user is responsible for de-allocating the memory owned by pointers
7476
* returned by functions. Typically pointers returned by *_create(...) functions
@@ -120,12 +122,6 @@ typedef struct kernel_LoggingConnection kernel_LoggingConnection;
120122
*/
121123
typedef struct kernel_ChainParameters kernel_ChainParameters;
122124

123-
/**
124-
* Opaque data structure for holding callbacks for reacting to events that may
125-
* be encountered during library operations.
126-
*/
127-
typedef struct kernel_Notifications kernel_Notifications;
128-
129125
/**
130126
* Opaque data structure for holding options for creating a new kernel context.
131127
*
@@ -599,19 +595,6 @@ const kernel_ChainParameters* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_chain_para
599595
*/
600596
void kernel_chain_parameters_destroy(const kernel_ChainParameters* chain_parameters);
601597

602-
/**
603-
* @brief Creates an object for holding the kernel notification callbacks.
604-
*
605-
* @param[in] callbacks Holds the callbacks that will be invoked by the kernel notifications.
606-
*/
607-
kernel_Notifications* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_notifications_create(
608-
kernel_NotificationInterfaceCallbacks callbacks);
609-
610-
/**
611-
* Destroy the kernel notifications.
612-
*/
613-
void kernel_notifications_destroy(kernel_Notifications* notifications);
614-
615598
/**
616599
* Creates an empty context options.
617600
*/
@@ -621,7 +604,7 @@ kernel_ContextOptions* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_context_options_c
621604
* @brief Sets the chain params for the context options. The context created
622605
* with the options will be configured for these chain parameters.
623606
*
624-
* @param[in] context_options Non-null, previously created with kernel_context_options_create.
607+
* @param[in] context_options Non-null, previously created by @ref kernel_context_options_create.
625608
* @param[in] chain_parameters Is set to the context options.
626609
*/
627610
void kernel_context_options_set_chainparams(
@@ -633,13 +616,13 @@ void kernel_context_options_set_chainparams(
633616
* @brief Set the kernel notifications for the context options. The context
634617
* created with the options will be configured with these notifications.
635618
*
636-
* @param[in] context_options Non-null, previously created with kernel_context_options_create.
619+
* @param[in] context_options Non-null, previously created by @ref kernel_context_options_create.
637620
* @param[in] notifications Is set to the context options.
638621
*/
639622
void kernel_context_options_set_notifications(
640623
kernel_ContextOptions* context_options,
641-
const kernel_Notifications* notifications
642-
) BITCOINKERNEL_ARG_NONNULL(1, 2);
624+
kernel_NotificationInterfaceCallbacks notifications
625+
) BITCOINKERNEL_ARG_NONNULL(1);
643626

644627
/**
645628
* @brief Set the validation interface callbacks for the context options. The
@@ -667,7 +650,7 @@ void kernel_context_options_destroy(kernel_ContextOptions* context_options);
667650
* context will assume mainnet chain parameters and won't attempt to call the
668651
* kernel notification callbacks.
669652
*
670-
* @param[in] context_options Nullable, created with kernel_context_options_create.
653+
* @param[in] context_options Nullable, created by @ref kernel_context_options_create.
671654
* @return The allocated kernel context, or null on error.
672655
*/
673656
kernel_Context* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_context_create(
@@ -748,8 +731,8 @@ void kernel_block_manager_options_destroy(kernel_BlockManagerOptions* block_mana
748731
* validation tasks as well as for retrieving data from the chain. It is only
749732
* valid for as long as the passed in context also remains in memory.
750733
*
751-
* @param[in] chainstate_manager_options Non-null, created by kernel_chainstate_manager_options_create.
752-
* @param[in] block_manager_options Non-null, created by kernel_block_manager_options_create.
734+
* @param[in] chainstate_manager_options Non-null, created by @ref kernel_chainstate_manager_options_create.
735+
* @param[in] block_manager_options Non-null, created by @ref kernel_block_manager_options_create.
753736
* @param[in] context Non-null, the created chainstate manager will associate with this
754737
* kernel context for the duration of its lifetime. The same context
755738
* needs to be used for later interactions with the chainstate manager.
@@ -774,7 +757,7 @@ kernel_ChainstateLoadOptions* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_chainstate
774757
/**
775758
* @brief Sets wipe block tree db in the chainstate load options.
776759
*
777-
* @param[in] chainstate_load_options Non-null, created with kernel_chainstate_load_options_create.
760+
* @param[in] chainstate_load_options Non-null, created by @ref kernel_chainstate_load_options_create.
778761
* @param[in] wipe_block_tree_db Set wipe block tree db.
779762
*/
780763
void kernel_chainstate_load_options_set_wipe_block_tree_db(
@@ -785,7 +768,7 @@ void kernel_chainstate_load_options_set_wipe_block_tree_db(
785768
/**
786769
* @brief Sets wipe chainstate db in the chainstate load options.
787770
*
788-
* @param[in] chainstate_load_options Non-null, created with kernel_chainstate_load_options_create.
771+
* @param[in] chainstate_load_options Non-null, created by @ref kernel_chainstate_load_options_create.
789772
* @param[in] wipe_chainstate_db Set wipe chainstate db.
790773
*/
791774
void kernel_chainstate_load_options_set_wipe_chainstate_db(
@@ -796,7 +779,7 @@ void kernel_chainstate_load_options_set_wipe_chainstate_db(
796779
/**
797780
* @brief Sets block tree db in memory in the chainstate load options.
798781
*
799-
* @param[in] chainstate_load_options Non-null, created with kernel_chainstate_load_options_create.
782+
* @param[in] chainstate_load_options Non-null, created by @ref kernel_chainstate_load_options_create.
800783
* @param[in] block_tree_db_in_memory Set block tree db in memory.
801784
*/
802785
void kernel_chainstate_load_options_set_block_tree_db_in_memory(
@@ -807,7 +790,7 @@ void kernel_chainstate_load_options_set_block_tree_db_in_memory(
807790
/**
808791
* @brief Sets chainstate db in memory in the chainstate load options.
809792
*
810-
* @param[in] chainstate_load_options Non-null, created with kernel_chainstate_load_options_create.
793+
* @param[in] chainstate_load_options Non-null, created by @ref kernel_chainstate_load_options_create.
811794
* @param[in] chainstate_db_in_memory Set chainstate db in memory.
812795
*/
813796
void kernel_chainstate_load_options_set_chainstate_db_in_memory(
@@ -825,7 +808,7 @@ void kernel_chainstate_load_options_destroy(kernel_ChainstateLoadOptions* chains
825808
* before doing validation tasks or interacting with its indexes.
826809
*
827810
* @param[in] context Non-null.
828-
* @param[in] chainstate_load_options Non-null, created by kernel_chainstate_load_options_create.
811+
* @param[in] chainstate_load_options Non-null, created by @ref kernel_chainstate_load_options_create.
829812
* @param[in] chainstate_manager Non-null, will load the chainstate(s) and initialize indexes.
830813
* @return True on success, false on error.
831814
*/

src/kernel/bitcoinkernel_wrapper.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,6 @@ template <typename T>
172172
class KernelNotifications
173173
{
174174
private:
175-
struct Deleter {
176-
void operator()(kernel_Notifications* ptr) const
177-
{
178-
kernel_notifications_destroy(ptr);
179-
}
180-
};
181-
182175
kernel_NotificationInterfaceCallbacks MakeCallbacks()
183176
{
184177
return kernel_NotificationInterfaceCallbacks{
@@ -201,10 +194,10 @@ class KernelNotifications
201194
};
202195
}
203196

204-
std::unique_ptr<kernel_Notifications, Deleter> m_notifications;
197+
const kernel_NotificationInterfaceCallbacks m_notifications;
205198

206199
public:
207-
KernelNotifications() : m_notifications{kernel_notifications_create(MakeCallbacks())} {}
200+
KernelNotifications() : m_notifications{MakeCallbacks()} {}
208201

209202
virtual ~KernelNotifications() = default;
210203

@@ -347,7 +340,7 @@ class ContextOptions
347340
template <typename T>
348341
void SetNotifications(KernelNotifications<T>& notifications) const noexcept
349342
{
350-
kernel_context_options_set_notifications(m_options.get(), notifications.m_notifications.get());
343+
kernel_context_options_set_notifications(m_options.get(), notifications.m_notifications);
351344
}
352345

353346
template <typename T>

src/test/kernel/test_kernel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ void run_verify_test(
197197
auto status = kernel_ScriptVerifyStatus::kernel_SCRIPT_VERIFY_OK;
198198

199199
if (taproot) {
200-
verify_script(
200+
assert(verify_script(
201201
spent_script_pubkey,
202202
amount,
203203
spending_tx,
204204
spent_outputs,
205205
input_index,
206206
kernel_SCRIPT_FLAGS_VERIFY_ALL,
207-
status);
207+
status));
208208
assert(status == kernel_SCRIPT_VERIFY_OK);
209209
} else {
210210
assert(!verify_script(
@@ -297,7 +297,7 @@ void script_verify_test()
297297
spent_outputs.emplace_back(taproot_spent_script_pubkey, 88480);
298298
run_verify_test(
299299
/*spent_script_pubkey*/ taproot_spent_script_pubkey,
300-
/*spending_tx*/ Transaction{hex_string_to_char_vec("01000000000101b9cb0da76784960e000d63f0453221aeeb6df97f2119d35c3051065bc9881eab0000000000fdffffff020000000000000000186a16546170726f6f74204654572120406269746275673432a059010000000000225120339ce7e165e67d93adb3fef88a6d4beed33f01fa876f05a225242b82a631abc00247304402204bf50f2fea3a2fbf4db8f0de602d9f41665fe153840c1b6f17c0c0abefa42f0b0220631fe0968b166b00cb3027c8817f50ce8353e9d5de43c29348b75b6600f231fc012102b14f0e661960252f8f37486e7fe27431c9f94627a617da66ca9678e6a2218ce1ffd30a00")},
300+
/*spending_tx*/ Transaction{hex_string_to_char_vec("01000000000101d1f1c1f8cdf6759167b90f52c9ad358a369f95284e841d7a2536cef31c0549580100000000fdffffff020000000000000000316a2f49206c696b65205363686e6f7272207369677320616e6420492063616e6e6f74206c69652e204062697462756734329e06010000000000225120a37c3903c8d0db6512e2b40b0dffa05e5a3ab73603ce8c9c4b7771e5412328f90140a60c383f71bac0ec919b1d7dbc3eb72dd56e7aa99583615564f9f99b8ae4e837b758773a5b2e4c51348854c8389f008e05029db7f464a5ff2e01d5e6e626174affd30a00")},
301301
/*spent_outputs*/ spent_outputs,
302302
/*amount*/ 88480,
303303
/*input_index*/ 0,

0 commit comments

Comments
 (0)