Skip to content

Commit 4cef0f9

Browse files
committed
Squashed 'libbitcoinkernel-sys/bitcoin/' changes from fc67047b7e1..34a8429ff3a
34a8429ff3a kernel: Add pure kernel bitcoin-chainstate 6e9834d65e8 kernel: Add functions to get the block hash from a block 5ade5c2c879 kernel: Add block index utility functions to C header edc970c16fc kernel: Add function to read block undo data from disk to C header 27ae05ee614 kernel: Add functions to read block from disk to C header 2a31ff87c85 kernel: Add function for copying block data to C header 18d44eb823d kernel: Add functions for the block validation state to C header 8a338185fa9 kernel: Add validation interface to C header abfb0549fdd kernel: Add interrupt function to C header fdf772a2918 kernel: Add import blocks function to C header a6175602cf5 kernel: Add chainstate load options for in-memory dbs in C header 72c57446910 kernel: Add options for reindexing in C header fe82b15ce02 kernel: Add block validation to C header 56b8a64947d Kernel: Add chainstate loading to kernel C header c3b34ce08d7 kernel: Add chainstate manager option for setting worker threads 3610be3b138 kernel: Add chainstate manager object to C header c194bea41f6 kernel: Add notifications context option to C header 691d89d846b kerenl: Add chain params context option to C header 407ca750cda kernel: Add kernel library context object ee3c4ea92cd kernel: Add logging to kernel library C header e6c610a7e03 kernel: Introduce initial kernel C header API REVERT: fc67047b7e1 kernel: Add pure kernel bitcoin-chainstate REVERT: e2116031253 kernel: Add functions to get the block hash from a block REVERT: 2ae6547941f kernel: Add block index utility functions to C header REVERT: f09d42fff2b kernel: Add function to read block undo data from disk to C header REVERT: 52aedd024b0 kernel: Add functions to read block from disk to C header REVERT: 6d2bdce9923 kernel: Add function for copying block data to C header REVERT: e3b16b2677a kernel: Add functions for the block validation state to C header REVERT: 8de0bd040f4 kernel: Add validation interface to C header REVERT: 84abd35f72a kernel: Add interrupt function to C header REVERT: 260fb3e0584 kernel: Add import blocks function to C header REVERT: 971bb20e9c8 kernel: Add chainstate load options for in-memory dbs in C header REVERT: 1af8c906fc7 kernel: Add options for reindexing in C header REVERT: 055d2ed419e kernel: Add block validation to C header REVERT: 39850656a04 Kernel: Add chainstate loading to kernel C header REVERT: 06d26f0bfa6 kernel: Add chainstate manager option for setting worker threads REVERT: a3d46f4bf64 kernel: Add chainstate manager object to C header REVERT: d2e2da933b7 kernel: Add notifications context option to C header REVERT: 1337539a0b3 kerenl: Add chain params context option to C header REVERT: 778330c21f0 kernel: Add kernel library context object REVERT: a54b59d8100 kernel: Add logging to kernel library C header REVERT: 4fe7162698d kernel: Introduce initial kernel C header API git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 34a8429ff3a870c0caaf4c4790becd86c5acde38
1 parent 24563d2 commit 4cef0f9

File tree

3 files changed

+64
-52
lines changed

3 files changed

+64
-52
lines changed

src/kernel/bitcoinkernel.cpp

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,22 @@ const Context* cast_const_context(const kernel_Context* context)
306306
return reinterpret_cast<const Context*>(context);
307307
}
308308

309+
const ChainstateManager::Options* cast_const_chainstate_manager_options(const kernel_ChainstateManagerOptions* options)
310+
{
311+
assert(options);
312+
return reinterpret_cast<const ChainstateManager::Options*>(options);
313+
}
314+
309315
ChainstateManager::Options* cast_chainstate_manager_options(kernel_ChainstateManagerOptions* options)
310316
{
311317
assert(options);
312318
return reinterpret_cast<ChainstateManager::Options*>(options);
313319
}
314320

315-
node::BlockManager::Options* cast_block_manager_options(kernel_BlockManagerOptions* options)
321+
const node::BlockManager::Options* cast_const_block_manager_options(const kernel_BlockManagerOptions* options)
316322
{
317323
assert(options);
318-
return reinterpret_cast<node::BlockManager::Options*>(options);
324+
return reinterpret_cast<const node::BlockManager::Options*>(options);
319325
}
320326

321327
ChainstateManager* cast_chainstate_manager(kernel_ChainstateManager* chainman)
@@ -330,6 +336,12 @@ node::ChainstateLoadOptions* cast_chainstate_load_options(kernel_ChainstateLoadO
330336
return reinterpret_cast<node::ChainstateLoadOptions*>(options);
331337
}
332338

339+
const node::ChainstateLoadOptions* cast_const_chainstate_load_options(const kernel_ChainstateLoadOptions* options)
340+
{
341+
assert(options);
342+
return reinterpret_cast<const node::ChainstateLoadOptions*>(options);
343+
}
344+
333345
std::shared_ptr<CBlock>* cast_cblocksharedpointer(kernel_Block* block)
334346
{
335347
assert(block);
@@ -354,16 +366,16 @@ const CBlock* cast_const_cblock(const kernel_BlockPointer* block)
354366
return reinterpret_cast<const CBlock*>(block);
355367
}
356368

357-
CBlockIndex* cast_block_index(kernel_BlockIndex* index)
369+
const CBlockIndex* cast_const_block_index(const kernel_BlockIndex* index)
358370
{
359371
assert(index);
360-
return reinterpret_cast<CBlockIndex*>(index);
372+
return reinterpret_cast<const CBlockIndex*>(index);
361373
}
362374

363-
CBlockUndo* cast_block_undo(kernel_BlockUndo* undo)
375+
const CBlockUndo* cast_const_block_undo(const kernel_BlockUndo* undo)
364376
{
365377
assert(undo);
366-
return reinterpret_cast<CBlockUndo*>(undo);
378+
return reinterpret_cast<const CBlockUndo*>(undo);
367379
}
368380

369381
} // namespace
@@ -412,7 +424,7 @@ void kernel_script_pubkey_destroy(kernel_ScriptPubkey* script_pubkey)
412424
}
413425
}
414426

415-
kernel_TransactionOutput* kernel_transaction_output_create(kernel_ScriptPubkey* script_pubkey_, int64_t amount)
427+
kernel_TransactionOutput* kernel_transaction_output_create(const kernel_ScriptPubkey* script_pubkey_, int64_t amount)
416428
{
417429
const auto& script_pubkey{*cast_script_pubkey(script_pubkey_)};
418430
const CAmount& value{amount};
@@ -593,7 +605,7 @@ kernel_Notifications* kernel_notifications_create(kernel_NotificationInterfaceCa
593605
return reinterpret_cast<kernel_Notifications*>(new KernelNotifications{callbacks});
594606
}
595607

596-
void kernel_notifications_destroy(const kernel_Notifications* notifications)
608+
void kernel_notifications_destroy(kernel_Notifications* notifications)
597609
{
598610
if (notifications) {
599611
delete cast_const_notifications(notifications);
@@ -752,7 +764,7 @@ void kernel_chainstate_manager_options_set_worker_threads_num(kernel_ChainstateM
752764
void kernel_chainstate_manager_options_destroy(kernel_ChainstateManagerOptions* options)
753765
{
754766
if (options) {
755-
delete cast_chainstate_manager_options(options);
767+
delete cast_const_chainstate_manager_options(options);
756768
}
757769
}
758770

@@ -778,17 +790,17 @@ kernel_BlockManagerOptions* kernel_block_manager_options_create(const kernel_Con
778790
void kernel_block_manager_options_destroy(kernel_BlockManagerOptions* options)
779791
{
780792
if (options) {
781-
delete cast_block_manager_options(options);
793+
delete cast_const_block_manager_options(options);
782794
}
783795
}
784796

785797
kernel_ChainstateManager* kernel_chainstate_manager_create(
786798
const kernel_Context* context_,
787-
kernel_ChainstateManagerOptions* chainman_opts_,
788-
kernel_BlockManagerOptions* blockman_opts_)
799+
const kernel_ChainstateManagerOptions* chainman_opts_,
800+
const kernel_BlockManagerOptions* blockman_opts_)
789801
{
790-
auto chainman_opts{cast_chainstate_manager_options(chainman_opts_)};
791-
auto blockman_opts{cast_block_manager_options(blockman_opts_)};
802+
auto chainman_opts{cast_const_chainstate_manager_options(chainman_opts_)};
803+
auto blockman_opts{cast_const_block_manager_options(blockman_opts_)};
792804
auto context{cast_const_context(context_)};
793805

794806
try {
@@ -840,16 +852,16 @@ void kernel_chainstate_load_options_set_chainstate_db_in_memory(
840852
void kernel_chainstate_load_options_destroy(kernel_ChainstateLoadOptions* chainstate_load_opts)
841853
{
842854
if (chainstate_load_opts) {
843-
delete cast_chainstate_load_options(chainstate_load_opts);
855+
delete cast_const_chainstate_load_options(chainstate_load_opts);
844856
}
845857
}
846858

847859
bool kernel_chainstate_manager_load_chainstate(const kernel_Context* context_,
848-
kernel_ChainstateLoadOptions* chainstate_load_opts_,
860+
const kernel_ChainstateLoadOptions* chainstate_load_opts_,
849861
kernel_ChainstateManager* chainman_)
850862
{
851863
try {
852-
auto& chainstate_load_opts{*cast_chainstate_load_options(chainstate_load_opts_)};
864+
const auto& chainstate_load_opts{*cast_const_chainstate_load_options(chainstate_load_opts_)};
853865
auto& chainman{*cast_chainstate_manager(chainman_)};
854866

855867
if (chainstate_load_opts.wipe_block_tree_db && !chainstate_load_opts.wipe_chainstate_db) {
@@ -1049,9 +1061,9 @@ kernel_BlockIndex* kernel_get_block_index_by_height(const kernel_Context* contex
10491061
return reinterpret_cast<kernel_BlockIndex*>(chainman->ActiveChain()[height]);
10501062
}
10511063

1052-
kernel_BlockIndex* kernel_get_next_block_index(const kernel_Context* context_, kernel_BlockIndex* block_index_, kernel_ChainstateManager* chainman_)
1064+
kernel_BlockIndex* kernel_get_next_block_index(const kernel_Context* context_, const kernel_BlockIndex* block_index_, kernel_ChainstateManager* chainman_)
10531065
{
1054-
auto block_index{cast_block_index(block_index_)};
1066+
const auto block_index{cast_const_block_index(block_index_)};
10551067
auto chainman{cast_chainstate_manager(chainman_)};
10561068

10571069
auto next_block_index{WITH_LOCK(::cs_main, return chainman->ActiveChain().Next(block_index))};
@@ -1063,9 +1075,9 @@ kernel_BlockIndex* kernel_get_next_block_index(const kernel_Context* context_, k
10631075
return reinterpret_cast<kernel_BlockIndex*>(next_block_index);
10641076
}
10651077

1066-
kernel_BlockIndex* kernel_get_previous_block_index(kernel_BlockIndex* block_index_)
1078+
kernel_BlockIndex* kernel_get_previous_block_index(const kernel_BlockIndex* block_index_)
10671079
{
1068-
CBlockIndex* block_index{cast_block_index(block_index_)};
1080+
const CBlockIndex* block_index{cast_const_block_index(block_index_)};
10691081

10701082
if (!block_index->pprev) {
10711083
LogTrace(BCLog::KERNEL, "The block index is the genesis, it has no previous.\n");
@@ -1077,10 +1089,10 @@ kernel_BlockIndex* kernel_get_previous_block_index(kernel_BlockIndex* block_inde
10771089

10781090
kernel_Block* kernel_read_block_from_disk(const kernel_Context* context_,
10791091
kernel_ChainstateManager* chainman_,
1080-
kernel_BlockIndex* block_index_)
1092+
const kernel_BlockIndex* block_index_)
10811093
{
10821094
auto chainman{cast_chainstate_manager(chainman_)};
1083-
CBlockIndex* block_index{cast_block_index(block_index_)};
1095+
const CBlockIndex* block_index{cast_const_block_index(block_index_)};
10841096

10851097
auto block{new std::shared_ptr<CBlock>(new CBlock{})};
10861098
if (!chainman->m_blockman.ReadBlockFromDisk(**block, *block_index)) {
@@ -1092,10 +1104,10 @@ kernel_Block* kernel_read_block_from_disk(const kernel_Context* context_,
10921104

10931105
kernel_BlockUndo* kernel_read_block_undo_from_disk(const kernel_Context* context_,
10941106
kernel_ChainstateManager* chainman_,
1095-
kernel_BlockIndex* block_index_)
1107+
const kernel_BlockIndex* block_index_)
10961108
{
10971109
auto chainman{cast_chainstate_manager(chainman_)};
1098-
auto block_index{cast_block_index(block_index_)};
1110+
const auto block_index{cast_const_block_index(block_index_)};
10991111

11001112
if (block_index->nHeight < 1) {
11011113
LogError("The genesis block does not have undo data.\n");
@@ -1115,30 +1127,30 @@ void kernel_block_index_destroy(kernel_BlockIndex* block_index)
11151127
return;
11161128
}
11171129

1118-
uint64_t kernel_block_undo_size(kernel_BlockUndo* block_undo_)
1130+
uint64_t kernel_block_undo_size(const kernel_BlockUndo* block_undo_)
11191131
{
1120-
auto block_undo{cast_block_undo(block_undo_)};
1132+
const auto block_undo{cast_const_block_undo(block_undo_)};
11211133
return block_undo->vtxundo.size();
11221134
}
11231135

11241136
void kernel_block_undo_destroy(kernel_BlockUndo* block_undo)
11251137
{
11261138
if (block_undo) {
1127-
delete cast_block_undo(block_undo);
1139+
delete cast_const_block_undo(block_undo);
11281140
}
11291141
}
11301142

1131-
uint64_t kernel_get_transaction_undo_size(kernel_BlockUndo* block_undo_, uint64_t transaction_undo_index)
1143+
uint64_t kernel_get_transaction_undo_size(const kernel_BlockUndo* block_undo_, uint64_t transaction_undo_index)
11321144
{
1133-
auto block_undo{cast_block_undo(block_undo_)};
1145+
const auto block_undo{cast_const_block_undo(block_undo_)};
11341146
return block_undo->vtxundo[transaction_undo_index].vprevout.size();
11351147
}
11361148

1137-
kernel_TransactionOutput* kernel_get_undo_output_by_index(kernel_BlockUndo* block_undo_,
1149+
kernel_TransactionOutput* kernel_get_undo_output_by_index(const kernel_BlockUndo* block_undo_,
11381150
uint64_t transaction_undo_index,
11391151
uint64_t output_index)
11401152
{
1141-
auto block_undo{cast_block_undo(block_undo_)};
1153+
const auto block_undo{cast_const_block_undo(block_undo_)};
11421154

11431155
if (transaction_undo_index >= block_undo->vtxundo.size()) {
11441156
LogInfo("transaction undo index is out of bounds.\n");
@@ -1156,15 +1168,15 @@ kernel_TransactionOutput* kernel_get_undo_output_by_index(kernel_BlockUndo* bloc
11561168
return reinterpret_cast<kernel_TransactionOutput*>(prevout);
11571169
}
11581170

1159-
int32_t kernel_block_index_get_height(kernel_BlockIndex* block_index_)
1171+
int32_t kernel_block_index_get_height(const kernel_BlockIndex* block_index_)
11601172
{
1161-
auto block_index{cast_block_index(block_index_)};
1173+
auto block_index{cast_const_block_index(block_index_)};
11621174
return block_index->nHeight;
11631175
}
11641176

1165-
kernel_BlockHash* kernel_block_index_get_block_hash(kernel_BlockIndex* block_index_)
1177+
kernel_BlockHash* kernel_block_index_get_block_hash(const kernel_BlockIndex* block_index_)
11661178
{
1167-
auto block_index{cast_block_index(block_index_)};
1179+
auto block_index{cast_const_block_index(block_index_)};
11681180
if (block_index->phashBlock == nullptr) {
11691181
return nullptr;
11701182
}

src/kernel/bitcoinkernel.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void kernel_script_pubkey_destroy(kernel_ScriptPubkey* script_pubkey);
486486
* @return The transaction output.
487487
*/
488488
kernel_TransactionOutput* kernel_transaction_output_create(
489-
kernel_ScriptPubkey* script_pubkey,
489+
const kernel_ScriptPubkey* script_pubkey,
490490
int64_t amount
491491
) BITCOINKERNEL_ARG_NONNULL(1);
492492

@@ -610,7 +610,7 @@ kernel_Notifications* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_notifications_crea
610610
/**
611611
* Destroy the kernel notifications.
612612
*/
613-
void kernel_notifications_destroy(const kernel_Notifications* notifications);
613+
void kernel_notifications_destroy(kernel_Notifications* notifications);
614614

615615
/**
616616
* Creates an empty context options.
@@ -741,8 +741,8 @@ void kernel_block_manager_options_destroy(kernel_BlockManagerOptions* block_mana
741741
*/
742742
kernel_ChainstateManager* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_chainstate_manager_create(
743743
const kernel_Context* context,
744-
kernel_ChainstateManagerOptions* chainstate_manager_options,
745-
kernel_BlockManagerOptions* block_manager_options
744+
const kernel_ChainstateManagerOptions* chainstate_manager_options,
745+
const kernel_BlockManagerOptions* block_manager_options
746746
) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
747747

748748
/**
@@ -863,7 +863,7 @@ void kernel_chainstate_load_options_destroy(kernel_ChainstateLoadOptions* chains
863863
*/
864864
bool BITCOINKERNEL_WARN_UNUSED_RESULT kernel_chainstate_manager_load_chainstate(
865865
const kernel_Context* context,
866-
kernel_ChainstateLoadOptions* chainstate_load_options,
866+
const kernel_ChainstateLoadOptions* chainstate_load_options,
867867
kernel_ChainstateManager* chainstate_manager
868868
) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
869869

@@ -1045,7 +1045,7 @@ kernel_BlockIndex* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_block_index_by_he
10451045
*/
10461046
kernel_BlockIndex* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_next_block_index(
10471047
const kernel_Context* context,
1048-
kernel_BlockIndex* block_index,
1048+
const kernel_BlockIndex* block_index,
10491049
kernel_ChainstateManager* chainstate_manager
10501050
) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
10511051

@@ -1057,7 +1057,7 @@ kernel_BlockIndex* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_next_block_index(
10571057
* @return The previous block index, or null on error or if the current block index is the genesis block.
10581058
*/
10591059
kernel_BlockIndex* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_previous_block_index(
1060-
kernel_BlockIndex* block_index
1060+
const kernel_BlockIndex* block_index
10611061
) BITCOINKERNEL_ARG_NONNULL(1);
10621062

10631063
/**
@@ -1072,7 +1072,7 @@ kernel_BlockIndex* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_previous_block_in
10721072
kernel_Block* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_read_block_from_disk(
10731073
const kernel_Context* context,
10741074
kernel_ChainstateManager* chainstate_manager,
1075-
kernel_BlockIndex* block_index
1075+
const kernel_BlockIndex* block_index
10761076
) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
10771077

10781078
/**
@@ -1087,7 +1087,7 @@ kernel_Block* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_read_block_from_disk(
10871087
kernel_BlockUndo* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_read_block_undo_from_disk(
10881088
const kernel_Context* context,
10891089
kernel_ChainstateManager* chainstate_manager,
1090-
kernel_BlockIndex* block_index
1090+
const kernel_BlockIndex* block_index
10911091
) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
10921092

10931093
/**
@@ -1103,7 +1103,7 @@ void kernel_block_index_destroy(kernel_BlockIndex* block_index);
11031103
* @return The number of transaction undo data in the block undo.
11041104
*/
11051105
uint64_t BITCOINKERNEL_WARN_UNUSED_RESULT kernel_block_undo_size(
1106-
kernel_BlockUndo* block_undo
1106+
const kernel_BlockUndo* block_undo
11071107
) BITCOINKERNEL_ARG_NONNULL(1);
11081108

11091109
/**
@@ -1120,7 +1120,7 @@ void kernel_block_undo_destroy(kernel_BlockUndo* block_undo);
11201120
* @return The number of previous transaction outputs in the transaction.
11211121
*/
11221122
uint64_t BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_transaction_undo_size(
1123-
kernel_BlockUndo* block_undo,
1123+
const kernel_BlockUndo* block_undo,
11241124
uint64_t transaction_undo_index
11251125
) BITCOINKERNEL_ARG_NONNULL(1);
11261126

@@ -1135,7 +1135,7 @@ uint64_t BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_transaction_undo_size(
11351135
* @return A transaction output pointer, or null on error.
11361136
*/
11371137
kernel_TransactionOutput* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_undo_output_by_index(
1138-
kernel_BlockUndo* block_undo,
1138+
const kernel_BlockUndo* block_undo,
11391139
uint64_t transaction_undo_index,
11401140
uint64_t output_index
11411141
) BITCOINKERNEL_ARG_NONNULL(1);
@@ -1147,7 +1147,7 @@ kernel_TransactionOutput* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_get_undo_outpu
11471147
* @return The block height.
11481148
*/
11491149
int32_t BITCOINKERNEL_WARN_UNUSED_RESULT kernel_block_index_get_height(
1150-
kernel_BlockIndex* block_index
1150+
const kernel_BlockIndex* block_index
11511151
) BITCOINKERNEL_ARG_NONNULL(1);
11521152

11531153
/**
@@ -1157,7 +1157,7 @@ int32_t BITCOINKERNEL_WARN_UNUSED_RESULT kernel_block_index_get_height(
11571157
* @return The block hash.
11581158
*/
11591159
kernel_BlockHash* BITCOINKERNEL_WARN_UNUSED_RESULT kernel_block_index_get_block_hash(
1160-
kernel_BlockIndex* block_index
1160+
const kernel_BlockIndex* block_index
11611161
) BITCOINKERNEL_ARG_NONNULL(1);
11621162

11631163
/**

src/kernel/bitcoinkernel_wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class KernelNotifications
173173
{
174174
private:
175175
struct Deleter {
176-
void operator()(const kernel_Notifications* ptr) const
176+
void operator()(kernel_Notifications* ptr) const
177177
{
178178
kernel_notifications_destroy(ptr);
179179
}
@@ -201,7 +201,7 @@ class KernelNotifications
201201
};
202202
}
203203

204-
std::unique_ptr<const kernel_Notifications, Deleter> m_notifications;
204+
std::unique_ptr<kernel_Notifications, Deleter> m_notifications;
205205

206206
public:
207207
KernelNotifications() : m_notifications{kernel_notifications_create(MakeCallbacks())} {}

0 commit comments

Comments
 (0)