Merge bitcoin/bitcoin#33820: kernel: trim Chain interface

66978a1a95 kernel: remove btck_chain_get_tip (stickies-v)
4dd7e6dc48 kernel: remove btck_chain_get_genesis (stickies-v)

Pull request description:

  Removes `btck_chain_get_genesis` and `btck_chain_get_tip`.

  They are trivially replaced with `btck_chain_get_by_height` (as indicated in the updated `bitcoinkernel_wrapper.h`), so I think it makes sense to trim the interface.

  For `btck_chain_get_tip`: on `master` we don't provide any guarantees that the returned block index still corresponds to the actual tip, so the extra call doesn't seem like a regression to me.

ACKs for top commit:
  TheCharlatan:
    ACK 66978a1a95
  janb84:
    ACK 66978a1a95

Tree-SHA512: f583fbb7f2e3f8f23afb57732b2cbe9e1d550bfc43c9a2619895ee30c27f5f3c5cd9e4ecb7e05b1f6ab9e11c368596ec9b733d67e06cfafb12326d88e8e4dd7d
This commit is contained in:
merge-script
2025-11-11 09:52:26 +00:00
4 changed files with 4 additions and 45 deletions

View File

@@ -1230,24 +1230,12 @@ const btck_Chain* btck_chainstate_manager_get_active_chain(const btck_Chainstate
return btck_Chain::ref(&WITH_LOCK(btck_ChainstateManager::get(chainman).m_chainman->GetMutex(), return btck_ChainstateManager::get(chainman).m_chainman->ActiveChain()));
}
const btck_BlockTreeEntry* btck_chain_get_tip(const btck_Chain* chain)
{
LOCK(::cs_main);
return btck_BlockTreeEntry::ref(btck_Chain::get(chain).Tip());
}
int btck_chain_get_height(const btck_Chain* chain)
{
LOCK(::cs_main);
return btck_Chain::get(chain).Height();
}
const btck_BlockTreeEntry* btck_chain_get_genesis(const btck_Chain* chain)
{
LOCK(::cs_main);
return btck_BlockTreeEntry::ref(btck_Chain::get(chain).Genesis());
}
const btck_BlockTreeEntry* btck_chain_get_by_height(const btck_Chain* chain, int height)
{
LOCK(::cs_main);

View File

@@ -1203,16 +1203,6 @@ BITCOINKERNEL_API btck_BlockValidationResult btck_block_validation_state_get_blo
*/
///@{
/**
* @brief Get the block tree entry of the current chain tip. Once returned,
* there is no guarantee that it remains in the active chain.
*
* @param[in] chain Non-null.
* @return The block tree entry of the current tip, or null if the chain is empty.
*/
BITCOINKERNEL_API const btck_BlockTreeEntry* BITCOINKERNEL_WARN_UNUSED_RESULT btck_chain_get_tip(
const btck_Chain* chain) BITCOINKERNEL_ARG_NONNULL(1);
/**
* @brief Return the height of the tip of the chain.
*
@@ -1222,15 +1212,6 @@ BITCOINKERNEL_API const btck_BlockTreeEntry* BITCOINKERNEL_WARN_UNUSED_RESULT bt
BITCOINKERNEL_API int32_t BITCOINKERNEL_WARN_UNUSED_RESULT btck_chain_get_height(
const btck_Chain* chain) BITCOINKERNEL_ARG_NONNULL(1);
/**
* @brief Get the block tree entry of the genesis block.
*
* @param[in] chain Non-null.
* @return The block tree entry of the genesis block, or null if the chain is empty.
*/
BITCOINKERNEL_API const btck_BlockTreeEntry* BITCOINKERNEL_WARN_UNUSED_RESULT btck_chain_get_genesis(
const btck_Chain* chain) BITCOINKERNEL_ARG_NONNULL(1);
/**
* @brief Retrieve a block tree entry by its height in the currently active chain.
* Once retrieved there is no guarantee that it remains in the active chain.

View File

@@ -968,11 +968,6 @@ class ChainView : public View<btck_Chain>
public:
explicit ChainView(const btck_Chain* ptr) : View{ptr} {}
BlockTreeEntry Tip() const
{
return btck_chain_get_tip(get());
}
int32_t Height() const
{
return btck_chain_get_height(get());
@@ -983,11 +978,6 @@ public:
return btck_chain_get_height(get()) + 1;
}
BlockTreeEntry Genesis() const
{
return btck_chain_get_genesis(get());
}
BlockTreeEntry GetByHeight(int height) const
{
auto index{btck_chain_get_by_height(get(), height)};

View File

@@ -664,7 +664,7 @@ void chainman_reindex_test(TestDirectory& test_directory)
// Sanity check some block retrievals
auto chain{chainman->GetChain()};
BOOST_CHECK_THROW(chain.GetByHeight(1000), std::runtime_error);
auto genesis_index{chain.Genesis()};
auto genesis_index{chain.Entries().front()};
BOOST_CHECK(!genesis_index.GetPrevious());
auto genesis_block_raw{chainman->ReadBlock(genesis_index).value().ToBytes()};
auto first_index{chain.GetByHeight(0)};
@@ -676,7 +676,7 @@ void chainman_reindex_test(TestDirectory& test_directory)
auto next_index{chain.GetByHeight(first_index.GetHeight() + 1)};
BOOST_CHECK(chain.Contains(next_index));
auto next_block_data{chainman->ReadBlock(next_index).value().ToBytes()};
auto tip_index{chain.Tip()};
auto tip_index{chain.Entries().back()};
auto tip_block_data{chainman->ReadBlock(tip_index).value().ToBytes()};
auto second_index{chain.GetByHeight(1)};
auto second_block{chainman->ReadBlock(second_index).value()};
@@ -755,7 +755,7 @@ void chainman_mainnet_validation_test(TestDirectory& test_directory)
auto chain{chainman->GetChain()};
BOOST_CHECK_EQUAL(chain.Height(), 1);
auto tip{chain.Tip()};
auto tip{chain.Entries().back()};
auto read_block{chainman->ReadBlock(tip)};
BOOST_REQUIRE(read_block);
check_equal(read_block.value().ToBytes(), raw_block);
@@ -851,7 +851,7 @@ BOOST_AUTO_TEST_CASE(btck_chainman_regtest_tests)
}
auto chain = chainman->GetChain();
auto tip = chain.Tip();
auto tip = chain.Entries().back();
auto read_block = chainman->ReadBlock(tip).value();
check_equal(read_block.ToBytes(), hex_string_to_byte_vec(REGTEST_BLOCK_DATA[REGTEST_BLOCK_DATA.size() - 1]));