kernel: remove btck_chain_get_genesis
What changed, and why it matters
This commit removes a redundant function that fetched the very first (genesis) block from a blockchain API. The same result can already be obtained through an existing general-purpose function. The change is a routine code cleanup with no security implications.
No security action required. Treat as normal refactoring/cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deletes btck_chain_get_genesis and its C++ wrapper Chain::Genesis(), because they are functionally equivalent to btck_chain_get_by_height(chain, 0). It updates the single test that used Chain::Genesis() to use chain.Entries().front() instead. No logic changes, no bug fixes, and no security-sensitive behavior is modified.
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hsrc/kernel/bitcoinkernel_wrapper.hsrc/test/kernel/test_kernel.cppInspect captured patch +1 / −21
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index 8bba3cf1..ee1bb985 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -1242,12 +1242,6 @@ int btck_chain_get_height(const btck_Chain* chain)
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);
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index add45f4b..3875832e 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -1222,15 +1222,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.
diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h
index 06a4ccfa..7bc3dd78 100644
--- a/src/kernel/bitcoinkernel_wrapper.h
+++ b/src/kernel/bitcoinkernel_wrapper.h
@@ -982,11 +982,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)};
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
index d9875ee1..eba1eb81 100644
--- a/src/test/kernel/test_kernel.cpp
+++ b/src/test/kernel/test_kernel.cpp
@@ -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)};
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.