Skip to content

Commit e765113

Browse files
committed
Squashed 'libbitcoinkernel-sys/bitcoin/' changes from 1ea43dc365c..e9f14a07ed8
e9f14a07ed8 kernel: Add Purpose section to header documentation 8d1a7e84cfb kernel: Allowing reducing exports 9da2c0abcee kernel: Add pure kernel bitcoin-chainstate 33325ffbbe9 Kernel: Add functions for working with outpoints 9fd8f6576fb kernel: Add block hash type and block tree utility functions to C header 07428ce9f46 kernel: Add function to read block undo data from disk to C header 99ee229fda4 kernel: Add functions to read block from disk to C header dcb8d495f2a kernel: Add function for copying block data to C header d42211bd8a4 kernel: Add functions for the block validation state to C header da8db18599c kernel: Add validation interface to C header d5dcd00fa80 kernel: Add interrupt function to C header 523a29fc73f kernel: Add import blocks function to C header e49b9881d90 kernel: Add chainstate load options for in-memory dbs in C header d21cdb3b23d kernel: Add options for reindexing in C header 09afc607fa0 kernel: Add block validation to C header 7333864cb04 kernel: Add chainstate loading when instantiating a ChainstateManager 71509f3856d kernel: Add chainstate manager option for setting worker threads 69f4e9f05aa kernel: Add chainstate manager object to C header 06cba4a4653 kernel: Add notifications context option to C header cd809dcae8f kernel: Add chain params context option to C header cf9f9b18474 kernel: Add kernel library context object REVERT: 1ea43dc365c kernel: Add Purpose section to header documentation REVERT: 6fb86d14a3e kernel: Allowing reducing exports REVERT: 0a3644da67e kernel: Add pure kernel bitcoin-chainstate REVERT: bb7276e1a72 Kernel: Add functions for working with outpoints REVERT: 5ef72e7c44b kernel: Add block hash type and block tree utility functions to C header REVERT: 43b7b7b9d28 kernel: Add function to read block undo data from disk to C header REVERT: 06a485c9ab1 kernel: Add functions to read block from disk to C header REVERT: 69c184b44f9 kernel: Add function for copying block data to C header REVERT: 0e973b20fcc kernel: Add functions for the block validation state to C header REVERT: 6c2181dc52f kernel: Add validation interface to C header REVERT: 4d8aa6b3fb1 kernel: Add interrupt function to C header REVERT: 2ecd926cf30 kernel: Add import blocks function to C header REVERT: efcfe2dfedf kernel: Add chainstate load options for in-memory dbs in C header REVERT: bc6788ab7dc kernel: Add options for reindexing in C header REVERT: e8f2f4fe225 kernel: Add block validation to C header REVERT: ffd4ae233ee kernel: Add chainstate loading when instantiating a ChainstateManager REVERT: 1167af89a8f kernel: Add chainstate manager option for setting worker threads REVERT: b88637f6967 kernel: Add chainstate manager object to C header REVERT: b4ff3ce0d34 kernel: Add notifications context option to C header REVERT: e3d62c1ad32 kernel: Add chain params context option to C header REVERT: a184a263df2 kernel: Add kernel library context object git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: e9f14a07ed8b8161840d739c24603539119ee5fd
1 parent f50d90f commit e765113

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

src/kernel/bitcoinkernel.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ struct LoggingConnection {
273273
}
274274
};
275275

276-
class KernelNotifications : public kernel::Notifications
276+
class KernelNotifications final : public kernel::Notifications
277277
{
278278
private:
279279
btck_NotificationInterfaceCallbacks m_cbs;
@@ -345,7 +345,7 @@ class KernelValidationInterface final : public CValidationInterface
345345
{
346346
if (m_cbs.block_checked) {
347347
m_cbs.block_checked(m_cbs.user_data,
348-
btck_Block::ref(new std::shared_ptr<const CBlock>{block}),
348+
btck_Block::copy(btck_Block::ref(&block)),
349349
btck_BlockValidationState::ref(&stateIn));
350350
}
351351
}
@@ -354,7 +354,7 @@ class KernelValidationInterface final : public CValidationInterface
354354
{
355355
if (m_cbs.pow_valid_block) {
356356
m_cbs.pow_valid_block(m_cbs.user_data,
357-
btck_Block::ref(new std::shared_ptr<const CBlock>{block}),
357+
btck_Block::copy(btck_Block::ref(&block)),
358358
btck_BlockTreeEntry::ref(pindex));
359359
}
360360
}
@@ -363,7 +363,7 @@ class KernelValidationInterface final : public CValidationInterface
363363
{
364364
if (m_cbs.block_connected) {
365365
m_cbs.block_connected(m_cbs.user_data,
366-
btck_Block::ref(new std::shared_ptr<const CBlock>{block}),
366+
btck_Block::copy(btck_Block::ref(&block)),
367367
btck_BlockTreeEntry::ref(pindex));
368368
}
369369
}
@@ -372,7 +372,7 @@ class KernelValidationInterface final : public CValidationInterface
372372
{
373373
if (m_cbs.block_disconnected) {
374374
m_cbs.block_disconnected(m_cbs.user_data,
375-
btck_Block::ref(new std::shared_ptr<const CBlock>{block}),
375+
btck_Block::copy(btck_Block::ref(&block)),
376376
btck_BlockTreeEntry::ref(pindex));
377377
}
378378
}
@@ -402,8 +402,7 @@ class Context
402402

403403
Context(const ContextOptions* options, bool& sane)
404404
: m_context{std::make_unique<kernel::Context>()},
405-
m_interrupt{std::make_unique<util::SignalInterrupt>()},
406-
m_signals{std::make_unique<ValidationSignals>(std::make_unique<ImmediateTaskRunner>())}
405+
m_interrupt{std::make_unique<util::SignalInterrupt>()}
407406
{
408407
if (options) {
409408
LOCK(options->m_mutex);
@@ -414,6 +413,7 @@ class Context
414413
m_notifications = options->m_notifications;
415414
}
416415
if (options->m_validation_interface) {
416+
m_signals = std::make_unique<ValidationSignals>(std::make_unique<ImmediateTaskRunner>());
417417
m_validation_interface = options->m_validation_interface;
418418
m_signals->RegisterSharedValidationInterface(m_validation_interface);
419419
}
@@ -434,7 +434,9 @@ class Context
434434

435435
~Context()
436436
{
437-
m_signals->UnregisterSharedValidationInterface(m_validation_interface);
437+
if (m_signals) {
438+
m_signals->UnregisterSharedValidationInterface(m_validation_interface);
439+
}
438440
}
439441
};
440442

@@ -757,19 +759,19 @@ btck_ChainParameters* btck_chain_parameters_create(const btck_ChainType chain_ty
757759
{
758760
switch (chain_type) {
759761
case btck_ChainType_MAINNET: {
760-
return btck_ChainParameters::create(*CChainParams::Main());
762+
return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::Main().release()));
761763
}
762764
case btck_ChainType_TESTNET: {
763-
return btck_ChainParameters::create(*CChainParams::TestNet());
765+
return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::TestNet().release()));
764766
}
765767
case btck_ChainType_TESTNET_4: {
766-
return btck_ChainParameters::create(*CChainParams::TestNet4());
768+
return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::TestNet4().release()));
767769
}
768770
case btck_ChainType_SIGNET: {
769-
return btck_ChainParameters::create(*CChainParams::SigNet({}));
771+
return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::SigNet({}).release()));
770772
}
771773
case btck_ChainType_REGTEST: {
772-
return btck_ChainParameters::create(*CChainParams::RegTest({}));
774+
return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::RegTest({}).release()));
773775
}
774776
}
775777
assert(false);
@@ -1022,7 +1024,6 @@ int btck_chainstate_manager_import_blocks(btck_ChainstateManager* chainman, cons
10221024
}
10231025
}
10241026
node::ImportBlocks(*btck_ChainstateManager::get(chainman).m_chainman, import_files);
1025-
btck_ChainstateManager::get(chainman).m_chainman->ActiveChainstate().ForceFlushStateToDisk();
10261027
} catch (const std::exception& e) {
10271028
LogError("Failed to import blocks: %s", e.what());
10281029
return -1;

src/kernel/bitcoinkernel.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ typedef struct {
366366
/**
367367
* A struct for holding the kernel notification callbacks. The user data
368368
* pointer may be used to point to user-defined structures to make processing
369-
* the notifications easier. Note that this makes it the user's responsibility
370-
* to ensure that the user_data outlives the kernel objects. Notifications can
369+
* the notifications easier.
370+
*
371+
* If user_data_destroy is provided, the kernel will automatically call this
372+
* callback to clean up user_data when the notification interface object is destroyed.
373+
* If user_data_destroy is NULL, it is the user's responsibility to ensure that
374+
* the user_data outlives the kernel objects. Notifications can
371375
* occur even as kernel objects are deleted, so care has to be taken to ensure
372376
* safe unwinding.
373377
*/
@@ -873,7 +877,7 @@ BITCOINKERNEL_API btck_Context* BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_co
873877
* when reindexing, importing or processing blocks.
874878
*
875879
* @param[in] context Non-null.
876-
* @return 0 if the interrupt was successfully, non-zero otherwise.
880+
* @return 0 if the interrupt was successful, non-zero otherwise.
877881
*/
878882
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_context_interrupt(
879883
btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
@@ -1014,7 +1018,7 @@ BITCOINKERNEL_API btck_ChainstateManager* BITCOINKERNEL_WARN_UNUSED_RESULT btck_
10141018
const btck_ChainstateManagerOptions* chainstate_manager_options) BITCOINKERNEL_ARG_NONNULL(1);
10151019

10161020
/**
1017-
* @brief Triggers the start of a reindex if the option was previously set for
1021+
* @brief Triggers the start of a reindex if the wipe options were previously set for
10181022
* the chainstate and block manager. Can also import an array of existing block
10191023
* files selected by the user.
10201024
*
@@ -1027,7 +1031,7 @@ BITCOINKERNEL_API btck_ChainstateManager* BITCOINKERNEL_WARN_UNUSED_RESULT btck_
10271031
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_chainstate_manager_import_blocks(
10281032
btck_ChainstateManager* chainstate_manager,
10291033
const char** block_file_paths_data, size_t* block_file_paths_lens,
1030-
size_t block_file_paths_data_len) BITCOINKERNEL_ARG_NONNULL(1, 2);
1034+
size_t block_file_paths_data_len) BITCOINKERNEL_ARG_NONNULL(1);
10311035

10321036
/**
10331037
* @brief Process and validate the passed in block with the chainstate

src/kernel/bitcoinkernel_wrapper.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,6 @@ class Block : public Handle<btck_Block, btck_block_copy, btck_block_destroy>
732732
{
733733
return write_bytes(get(), btck_block_to_bytes);
734734
}
735-
736-
friend class ChainMan;
737735
};
738736

739737
inline void logging_disable()
@@ -803,9 +801,6 @@ class BlockTreeEntry : public View<btck_BlockTreeEntry>
803801
{
804802
return BlockHashView{btck_block_tree_entry_get_block_hash(get())};
805803
}
806-
807-
friend class ChainMan;
808-
friend class Chain;
809804
};
810805

811806
class KernelNotifications
@@ -873,7 +868,7 @@ class ChainParams : public Handle<btck_ChainParameters, btck_chain_parameters_co
873868
: Handle{btck_chain_parameters_create(static_cast<btck_ChainType>(chain_type))} {}
874869
};
875870

876-
class ContextOptions : UniqueHandle<btck_ContextOptions, btck_context_options_destroy>
871+
class ContextOptions : public UniqueHandle<btck_ContextOptions, btck_context_options_destroy>
877872
{
878873
public:
879874
ContextOptions() : UniqueHandle{btck_context_options_create()} {}
@@ -921,8 +916,6 @@ class ContextOptions : UniqueHandle<btck_ContextOptions, btck_context_options_de
921916
.block_disconnected = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->BlockDisconnected(Block{block}, BlockTreeEntry{entry}); },
922917
});
923918
}
924-
925-
friend class Context;
926919
};
927920

928921
class Context : public Handle<btck_Context, btck_context_copy, btck_context_destroy>
@@ -940,7 +933,7 @@ class Context : public Handle<btck_Context, btck_context_copy, btck_context_dest
940933
}
941934
};
942935

943-
class ChainstateManagerOptions : UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
936+
class ChainstateManagerOptions : public UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
944937
{
945938
public:
946939
ChainstateManagerOptions(const Context& context, const std::string& data_dir, const std::string& blocks_dir)
@@ -967,8 +960,6 @@ class ChainstateManagerOptions : UniqueHandle<btck_ChainstateManagerOptions, btc
967960
{
968961
btck_chainstate_manager_options_update_chainstate_db_in_memory(get(), chainstate_db_in_memory);
969962
}
970-
971-
friend class ChainMan;
972963
};
973964

974965
class ChainView : public View<btck_Chain>

src/test/kernel/test_kernel.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,6 @@ std::unique_ptr<ChainMan> create_chainman(TestDirectory& test_directory,
635635
bool chainstate_db_in_memory,
636636
Context& context)
637637
{
638-
auto mainnet_test_directory{TestDirectory{"mainnet_test_bitcoin_kernel"}};
639-
640638
ChainstateManagerOptions chainman_opts{context, test_directory.m_directory.string(), (test_directory.m_directory / "blocks").string()};
641639

642640
if (reindex) {
@@ -658,8 +656,6 @@ std::unique_ptr<ChainMan> create_chainman(TestDirectory& test_directory,
658656

659657
void chainman_reindex_test(TestDirectory& test_directory)
660658
{
661-
auto mainnet_test_directory{TestDirectory{"mainnet_test_bitcoin_kernel"}};
662-
663659
auto notifications{std::make_shared<TestKernelNotifications>()};
664660
auto context{create_context(notifications, ChainType::MAINNET)};
665661
auto chainman{create_chainman(test_directory, true, false, false, false, context)};

0 commit comments

Comments
 (0)