rpc, test: Address feedback from #29668
What changed, and why it matters
This commit is a small cleanup following an earlier pull request. It rewrites one boolean condition in a clearer but equivalent way, updates a user-facing help string to describe a value more accurately, and makes some internal variables and function parameters read-only (const). There is no indication it fixes an active security bug or changes behavior in a way attackers could exploit.
No security action required. Treat as normal code review / merge.
Security signals we found
No security-relevant behavioral change in the logic
Boolean rewrite is semantically equivalent
Help text clarification only
Const-correctness and include cleanup only
Evidence from the diff
The change in src/rpc/blockchain.cpp simplifies !((chain_tip->nStatus & BLOCK_HAVE_MASK) == BLOCK_HAVE_MASK) to (chain_tip->nStatus & BLOCK_HAVE_MASK) != BLOCK_HAVE_MASK, which is logically equivalent. It also updates the RPC help text for pruneheight from ‘height of the last block pruned, plus one’ to ‘the first block unpruned, all previous blocks were pruned’. The header adds missing includes (threadsafety.h, <optional>) and a forward declaration for CChain. The test file marks chain and blockman references as const and marks the helper function parameters as const. These are code-quality and documentation improvements rather than a security fix.
Changed components
src/rpc/blockchain.cppsrc/rpc/blockchain.hsrc/test/blockchain_tests.cppInspect captured patch +8 / −5
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index a883570f..d7e316dd 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -864,7 +864,7 @@ std::optional<int> GetPruneHeight(const BlockManager& blockman, const CChain& ch
if (!first_block || !chain_tip) return std::nullopt;
// If the chain tip is pruned, everything is pruned.
- if (!((chain_tip->nStatus & BLOCK_HAVE_MASK) == BLOCK_HAVE_MASK)) return chain_tip->nHeight;
+ if ((chain_tip->nStatus & BLOCK_HAVE_MASK) != BLOCK_HAVE_MASK) return chain_tip->nHeight;
const auto& first_unpruned{blockman.GetFirstBlock(*chain_tip, /*status_mask=*/BLOCK_HAVE_MASK, first_block)};
if (&first_unpruned == first_block) {
@@ -1354,7 +1354,7 @@ RPCHelpMan getblockchaininfo()
{RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"},
{RPCResult::Type::NUM, "size_on_disk", "the estimated size of the block and undo files on disk"},
{RPCResult::Type::BOOL, "pruned", "if the blocks are subject to pruning"},
- {RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "height of the last block pruned, plus one (only present if pruning is enabled)"},
+ {RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "the first block unpruned, all previous blocks were pruned (only present if pruning is enabled)"},
{RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"},
{RPCResult::Type::NUM, "prune_target_size", /*optional=*/true, "the target size used by pruning (only present if automatic pruning is enabled)"},
{RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "the block challenge (aka. block script), in hexadecimal (only present if the current network is a signet)"},
diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h
index d14a43b2..efb06ac2 100644
--- a/src/rpc/blockchain.h
+++ b/src/rpc/blockchain.h
@@ -9,15 +9,18 @@
#include <core_io.h>
#include <streams.h>
#include <sync.h>
+#include <threadsafety.h>
#include <util/fs.h>
#include <validation.h>
#include <any>
#include <cstdint>
+#include <optional>
#include <vector>
class CBlock;
class CBlockIndex;
+class CChain;
class Chainstate;
class UniValue;
namespace node {
diff --git a/src/test/blockchain_tests.cpp b/src/test/blockchain_tests.cpp
index c6b35e32..c160f4e2 100644
--- a/src/test/blockchain_tests.cpp
+++ b/src/test/blockchain_tests.cpp
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target)
//! Prune chain from height down to genesis block and check that
//! GetPruneHeight returns the correct value
-static void CheckGetPruneHeight(node::BlockManager& blockman, CChain& chain, int height) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
+static void CheckGetPruneHeight(const node::BlockManager& blockman, const CChain& chain, int height) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{
AssertLockHeld(::cs_main);
@@ -98,8 +98,8 @@ static void CheckGetPruneHeight(node::BlockManager& blockman, CChain& chain, int
BOOST_FIXTURE_TEST_CASE(get_prune_height, TestChain100Setup)
{
LOCK(::cs_main);
- auto& chain = m_node.chainman->ActiveChain();
- auto& blockman = m_node.chainman->m_blockman;
+ const auto& chain = m_node.chainman->ActiveChain();
+ const auto& blockman = m_node.chainman->m_blockman;
// Fresh chain of 100 blocks without any pruned blocks, so std::nullopt should be returned
BOOST_CHECK(!GetPruneHeight(blockman, chain).has_value());
Why this scored 17/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.