Skip to content

Commit 1797bdf

Browse files
committed
Squashed 'libbitcoinkernel-sys/bitcoin/' changes from e9f14a07ed8..e95efc00842
e95efc00842 kernel: Add Purpose section to header documentation 6b61ae6cbfb kernel: Allowing reducing exports d0f3c29c5a6 kernel: Add pure kernel bitcoin-chainstate 574ca377557 Kernel: Add functions for working with outpoints dc91006a7f5 kernel: Add block hash type and block tree utility functions to C header 06e8f52f589 kernel: Add function to read block undo data from disk to C header 5103abeb636 kernel: Add functions to read block from disk to C header 68b2a8d7b7c kernel: Add function for copying block data to C header 6970d6f7f63 kernel: Add functions for the block validation state to C header ccefe9f8f8c kernel: Add validation interface to C header 5c8c23b9fe1 kernel: Add interrupt function to C header eb029703f81 kernel: Add import blocks function to C header 3d969fae26f kernel: Add chainstate load options for in-memory dbs in C header 5215d05b4b6 kernel: Add options for reindexing in C header cd83907b1d9 kernel: Add block validation to C header 73b92d519db kernel: Add chainstate loading when instantiating a ChainstateManager c39464d1975 kernel: Add chainstate manager option for setting worker threads c1a6def012a kernel: Add chainstate manager object to C header REVERT: e9f14a07ed8 kernel: Add Purpose section to header documentation REVERT: 8d1a7e84cfb kernel: Allowing reducing exports REVERT: 9da2c0abcee kernel: Add pure kernel bitcoin-chainstate REVERT: 33325ffbbe9 Kernel: Add functions for working with outpoints REVERT: 9fd8f6576fb kernel: Add block hash type and block tree utility functions to C header REVERT: 07428ce9f46 kernel: Add function to read block undo data from disk to C header REVERT: 99ee229fda4 kernel: Add functions to read block from disk to C header REVERT: dcb8d495f2a kernel: Add function for copying block data to C header REVERT: d42211bd8a4 kernel: Add functions for the block validation state to C header REVERT: da8db18599c kernel: Add validation interface to C header REVERT: d5dcd00fa80 kernel: Add interrupt function to C header REVERT: 523a29fc73f kernel: Add import blocks function to C header REVERT: e49b9881d90 kernel: Add chainstate load options for in-memory dbs in C header REVERT: d21cdb3b23d kernel: Add options for reindexing in C header REVERT: 09afc607fa0 kernel: Add block validation to C header REVERT: 7333864cb04 kernel: Add chainstate loading when instantiating a ChainstateManager REVERT: 71509f3856d kernel: Add chainstate manager option for setting worker threads REVERT: 69f4e9f05aa kernel: Add chainstate manager object to C header git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: e95efc00842d5d0df96ee9294cdf818741be539e
1 parent e765113 commit 1797bdf

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int main(int argc, char* argv[])
153153

154154
logging_set_options(logging_options);
155155

156-
Logger logger{std::make_unique<KernelLog>(KernelLog{})};
156+
Logger logger{std::make_unique<KernelLog>()};
157157

158158
ContextOptions options{};
159159
ChainParams params{ChainType::MAINNET};

src/kernel/bitcoinkernel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,16 +1232,19 @@ const btck_Chain* btck_chainstate_manager_get_active_chain(const btck_Chainstate
12321232

12331233
const btck_BlockTreeEntry* btck_chain_get_tip(const btck_Chain* chain)
12341234
{
1235+
LOCK(::cs_main);
12351236
return btck_BlockTreeEntry::ref(btck_Chain::get(chain).Tip());
12361237
}
12371238

12381239
int btck_chain_get_height(const btck_Chain* chain)
12391240
{
1241+
LOCK(::cs_main);
12401242
return btck_Chain::get(chain).Height();
12411243
}
12421244

12431245
const btck_BlockTreeEntry* btck_chain_get_genesis(const btck_Chain* chain)
12441246
{
1247+
LOCK(::cs_main);
12451248
return btck_BlockTreeEntry::ref(btck_Chain::get(chain).Genesis());
12461249
}
12471250

src/kernel/bitcoinkernel.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,8 @@ BITCOINKERNEL_API btck_ChainstateManager* BITCOINKERNEL_WARN_UNUSED_RESULT btck_
10181018
const btck_ChainstateManagerOptions* chainstate_manager_options) BITCOINKERNEL_ARG_NONNULL(1);
10191019

10201020
/**
1021-
* @brief Triggers the start of a reindex if the wipe options were previously set for
1022-
* the chainstate and block manager. Can also import an array of existing block
1021+
* @brief Triggers the start of a reindex if the wipe options were previously
1022+
* set for the chainstate manager. Can also import an array of existing block
10231023
* files selected by the user.
10241024
*
10251025
* @param[in] chainstate_manager Non-null.
@@ -1058,11 +1058,13 @@ BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_chainstate_manager_p
10581058
/**
10591059
* @brief Returns the best known currently active chain. Its lifetime is
10601060
* dependent on the chainstate manager. It can be thought of as a view on a
1061-
* vector of block tree entries that form the best chain. This means state
1062-
* transitions within the chainstate manager, e.g. processing blocks, will
1063-
* change the chain. Data retrieved from this chain is only consistent up to
1064-
* the point when new data is processed in the chainstate manager. It is the
1065-
* user's responsibility to guard against these inconsistencies.
1061+
* vector of block tree entries that form the best chain. The returned chain
1062+
* reference always points to the currently active best chain. However, state
1063+
* transitions within the chainstate manager (e.g., processing blocks) will
1064+
* update the chain's contents. Data retrieved from this chain is only
1065+
* consistent up to the point when new data is processed in the chainstate
1066+
* manager. It is the user's responsibility to guard against these
1067+
* inconsistencies.
10661068
*
10671069
* @param[in] chainstate_manager Non-null.
10681070
* @return The chain.

src/kernel/bitcoinkernel_wrapper.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,9 +1136,11 @@ class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_de
11361136
return ChainView{btck_chainstate_manager_get_active_chain(get())};
11371137
}
11381138

1139-
BlockTreeEntry GetBlockTreeEntry(const BlockHash& block_hash) const
1139+
std::optional<BlockTreeEntry> GetBlockTreeEntry(const BlockHash& block_hash) const
11401140
{
1141-
return btck_chainstate_manager_get_block_tree_entry_by_hash(get(), block_hash.get());
1141+
auto entry{btck_chainstate_manager_get_block_tree_entry_by_hash(get(), block_hash.get())};
1142+
if (!entry) return std::nullopt;
1143+
return entry;
11421144
}
11431145

11441146
std::optional<Block> ReadBlock(const BlockTreeEntry& entry) const

src/test/kernel/test_kernel.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,9 @@ class TestValidationInterface : public ValidationInterface
148148

149149
void BlockChecked(Block block, const BlockValidationState state) override
150150
{
151-
{
151+
if (m_expected_valid_block.has_value()) {
152152
auto ser_block{block.ToBytes()};
153-
if (m_expected_valid_block.has_value()) {
154-
check_equal(m_expected_valid_block.value(), ser_block);
155-
}
153+
check_equal(m_expected_valid_block.value(), ser_block);
156154
}
157155

158156
auto mode{state.GetValidationMode()};
@@ -600,7 +598,7 @@ Context create_context(std::shared_ptr<TestKernelNotifications> notifications, C
600598

601599
BOOST_AUTO_TEST_CASE(btck_chainman_tests)
602600
{
603-
Logger logger{std::make_unique<TestLog>(TestLog{})};
601+
Logger logger{std::make_unique<TestLog>()};
604602
auto test_directory{TestDirectory{"chainman_test_bitcoin_kernel"}};
605603

606604
{ // test with default context
@@ -690,7 +688,8 @@ void chainman_reindex_test(TestDirectory& test_directory)
690688

691689
auto second_hash{second_index.GetHash()};
692690
auto another_second_index{chainman->GetBlockTreeEntry(second_hash)};
693-
auto another_second_height{another_second_index.GetHeight()};
691+
BOOST_CHECK(another_second_index);
692+
auto another_second_height{another_second_index->GetHeight()};
694693
auto second_block_hash{second_block.GetHash()};
695694
check_equal(second_block_hash.ToBytes(), second_hash.ToBytes());
696695
BOOST_CHECK_EQUAL(second_height, another_second_height);
@@ -904,25 +903,34 @@ BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
904903
}
905904
}
906905

906+
// Read spent outputs for current tip and its previous block
907907
BlockSpentOutputs block_spent_outputs{chainman->ReadBlockSpentOutputs(tip)};
908908
BlockSpentOutputs block_spent_outputs_prev{chainman->ReadBlockSpentOutputs(*tip.GetPrevious())};
909909
CheckHandle(block_spent_outputs, block_spent_outputs_prev);
910910
CheckRange(block_spent_outputs_prev.TxsSpentOutputs(), block_spent_outputs_prev.Count());
911911
BOOST_CHECK_EQUAL(block_spent_outputs.Count(), 1);
912+
913+
// Get transaction spent outputs from the last transaction in the two blocks
912914
TransactionSpentOutputsView transaction_spent_outputs{block_spent_outputs.GetTxSpentOutputs(block_spent_outputs.Count() - 1)};
913915
TransactionSpentOutputs owned_transaction_spent_outputs{transaction_spent_outputs};
914916
TransactionSpentOutputs owned_transaction_spent_outputs_prev{block_spent_outputs_prev.GetTxSpentOutputs(block_spent_outputs_prev.Count() - 1)};
915917
CheckHandle(owned_transaction_spent_outputs, owned_transaction_spent_outputs_prev);
916918
CheckRange(transaction_spent_outputs.Coins(), transaction_spent_outputs.Count());
919+
920+
// Get the last coin from the transaction spent outputs
917921
CoinView coin{transaction_spent_outputs.GetCoin(transaction_spent_outputs.Count() - 1)};
918922
BOOST_CHECK(!coin.IsCoinbase());
919923
Coin owned_coin{coin};
920924
Coin owned_coin_prev{owned_transaction_spent_outputs_prev.GetCoin(owned_transaction_spent_outputs_prev.Count() - 1)};
921925
CheckHandle(owned_coin, owned_coin_prev);
926+
927+
// Validate coin properties
922928
TransactionOutputView output = coin.GetOutput();
923929
uint32_t coin_height = coin.GetConfirmationHeight();
924930
BOOST_CHECK_EQUAL(coin_height, 205);
925931
BOOST_CHECK_EQUAL(output.Amount(), 100000000);
932+
933+
// Test script pubkey serialization
926934
auto script_pubkey = output.GetScriptPubkey();
927935
auto script_pubkey_bytes{script_pubkey.ToBytes()};
928936
BOOST_CHECK_EQUAL(script_pubkey_bytes.size(), 22);

0 commit comments

Comments
 (0)