mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
rpc, test: Address feedback from #29668
This commit is contained in:
parent
adabfbc237
commit
d855c594c3
3 changed files with 11 additions and 8 deletions
|
@ -799,16 +799,16 @@ 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{*CHECK_NONFATAL(blockman.GetFirstBlock(*chain_tip, /*status_mask=*/BLOCK_HAVE_MASK, first_block))};
|
||||
if (&first_unpruned == first_block) {
|
||||
const CBlockIndex* first_unpruned{CHECK_NONFATAL(blockman.GetFirstBlock(*chain_tip, /*status_mask=*/BLOCK_HAVE_MASK, first_block))};
|
||||
if (first_unpruned == first_block) {
|
||||
// All blocks between first_block and chain_tip have data, so nothing is pruned.
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Block before the first unpruned block is the last pruned block.
|
||||
return CHECK_NONFATAL(first_unpruned.pprev)->nHeight;
|
||||
return CHECK_NONFATAL(first_unpruned->pprev)->nHeight;
|
||||
}
|
||||
|
||||
static RPCHelpMan pruneblockchain()
|
||||
|
@ -1285,7 +1285,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)"},
|
||||
(IsDeprecatedRPCEnabled("warnings") ?
|
||||
|
|
|
@ -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 <optional>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
class CBlock;
|
||||
class CBlockIndex;
|
||||
class CChain;
|
||||
class Chainstate;
|
||||
class UniValue;
|
||||
namespace node {
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue