What changed, and why it matters
This commit removes a convenience function called btck_chain_get_tip from the Bitcoin Core libbitcoinkernel API. The function simply returned the current tip of the blockchain, but the project decided it was redundant because callers can get the same information by combining two other existing functions. The change is a small API cleanup with no security relevance.
No security action required; treat as routine API cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes btck_chain_get_tip and its C++ wrapper ChainView::Tip(). Callers are updated to use chain.Entries().back() instead. The commit message explicitly states the removed function provided no stronger consistency guarantees than the equivalent height-based lookup, so this is a pure refactoring/de-duplication of the public kernel API surface.
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hsrc/kernel/bitcoinkernel_wrapper.hsrc/test/kernel/test_kernel.cppInspect captured patch +3 / −24
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index ee1bb985..240255bb 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -1230,12 +1230,6 @@ 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);
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index 3875832e..4c94b59f 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -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.
*
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index 7bc3dd78..63fd852d 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -967,11 +967,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());
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index eba1eb81..e1c9376d 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -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]));
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.