mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 13:02:38 +02:00
move-mostly: Make fHavePruned a BlockMan member
[META] In the next commit, we move the clearing of fHavePruned to BlockManager::Unload()
This commit is contained in:
parent
c96524113c
commit
3308ecd3fc
@ -40,7 +40,7 @@ static void BlockToJsonVerbose(benchmark::Bench& bench)
|
||||
{
|
||||
TestBlockAndIndex data;
|
||||
bench.run([&] {
|
||||
auto univalue = blockToJSON(data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||
ankerl::nanobench::doNotOptimizeAway(univalue);
|
||||
});
|
||||
}
|
||||
@ -50,7 +50,7 @@ BENCHMARK(BlockToJsonVerbose);
|
||||
static void BlockToJsonVerboseWrite(benchmark::Bench& bench)
|
||||
{
|
||||
TestBlockAndIndex data;
|
||||
auto univalue = blockToJSON(data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
|
||||
bench.run([&] {
|
||||
auto str = univalue.write();
|
||||
ankerl::nanobench::doNotOptimizeAway(str);
|
||||
|
@ -109,7 +109,6 @@ using node::LoadChainstate;
|
||||
using node::NodeContext;
|
||||
using node::ThreadImport;
|
||||
using node::VerifyLoadedChainstate;
|
||||
using node::fHavePruned;
|
||||
using node::fPruneMode;
|
||||
using node::fReindex;
|
||||
using node::nPruneTarget;
|
||||
@ -1480,7 +1479,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
try {
|
||||
uiInterface.InitMessage(_("Verifying blocks…").translated);
|
||||
auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
|
||||
if (fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
|
||||
if (chainman.m_blockman.fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
|
||||
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
|
||||
MIN_BLOCKS_TO_KEEP);
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
namespace node {
|
||||
std::atomic_bool fImporting(false);
|
||||
std::atomic_bool fReindex(false);
|
||||
bool fHavePruned = false;
|
||||
bool fPruneMode = false;
|
||||
uint64_t nPruneTarget = 0;
|
||||
|
||||
@ -390,7 +389,7 @@ const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool IsBlockPruned(const CBlockIndex* pblockindex)
|
||||
bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
|
||||
|
@ -45,8 +45,6 @@ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
|
||||
extern std::atomic_bool fImporting;
|
||||
extern std::atomic_bool fReindex;
|
||||
/** Pruning-related variables and constants */
|
||||
/** True if any block files have ever been pruned. */
|
||||
extern bool fHavePruned;
|
||||
/** True if we're running in -prune mode. */
|
||||
extern bool fPruneMode;
|
||||
/** Number of MiB of block files that we're trying to stay below. */
|
||||
@ -171,15 +169,18 @@ public:
|
||||
//! Returns last CBlockIndex* that is a checkpoint
|
||||
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
/** True if any block files have ever been pruned. */
|
||||
bool fHavePruned = false;
|
||||
|
||||
//! Check whether the block associated with this index entry is pruned or not.
|
||||
bool IsBlockPruned(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
~BlockManager()
|
||||
{
|
||||
Unload();
|
||||
}
|
||||
};
|
||||
|
||||
//! Check whether the block associated with this index entry is pruned or not.
|
||||
bool IsBlockPruned(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
void CleanupBlockRevFiles();
|
||||
|
||||
/** Open a block file (blk?????.dat) */
|
||||
|
@ -65,7 +65,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
||||
|
||||
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
|
||||
// in the past, but is now trying to run unpruned.
|
||||
if (fHavePruned && !fPruneMode) {
|
||||
if (chainman.m_blockman.fHavePruned && !fPruneMode) {
|
||||
return ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX;
|
||||
}
|
||||
|
||||
|
@ -645,7 +645,7 @@ public:
|
||||
bool havePruned() override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return node::fHavePruned;
|
||||
return m_node.chainman->m_blockman.fHavePruned;
|
||||
}
|
||||
bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
|
||||
bool isInitialBlockDownload() override {
|
||||
|
11
src/rest.cpp
11
src/rest.cpp
@ -37,7 +37,6 @@
|
||||
#include <univalue.h>
|
||||
|
||||
using node::GetTransaction;
|
||||
using node::IsBlockPruned;
|
||||
using node::NodeContext;
|
||||
using node::ReadBlockFromDisk;
|
||||
|
||||
@ -295,10 +294,10 @@ static bool rest_block(const std::any& context,
|
||||
CBlock block;
|
||||
const CBlockIndex* pblockindex = nullptr;
|
||||
const CBlockIndex* tip = nullptr;
|
||||
ChainstateManager* maybe_chainman = GetChainman(context, req);
|
||||
if (!maybe_chainman) return false;
|
||||
ChainstateManager& chainman = *maybe_chainman;
|
||||
{
|
||||
ChainstateManager* maybe_chainman = GetChainman(context, req);
|
||||
if (!maybe_chainman) return false;
|
||||
ChainstateManager& chainman = *maybe_chainman;
|
||||
LOCK(cs_main);
|
||||
tip = chainman.ActiveChain().Tip();
|
||||
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
@ -306,7 +305,7 @@ static bool rest_block(const std::any& context,
|
||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
|
||||
}
|
||||
|
||||
if (IsBlockPruned(pblockindex))
|
||||
if (chainman.m_blockman.IsBlockPruned(pblockindex))
|
||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
|
||||
|
||||
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
|
||||
@ -333,7 +332,7 @@ static bool rest_block(const std::any& context,
|
||||
}
|
||||
|
||||
case RESTResponseFormat::JSON: {
|
||||
UniValue objBlock = blockToJSON(block, tip, pblockindex, tx_verbosity);
|
||||
UniValue objBlock = blockToJSON(chainman.m_blockman, block, tip, pblockindex, tx_verbosity);
|
||||
std::string strJSON = objBlock.write() + "\n";
|
||||
req->WriteHeader("Content-Type", "application/json");
|
||||
req->WriteReply(HTTP_OK, strJSON);
|
||||
|
@ -54,7 +54,6 @@ using node::BlockManager;
|
||||
using node::CCoinsStats;
|
||||
using node::CoinStatsHashType;
|
||||
using node::GetUTXOStats;
|
||||
using node::IsBlockPruned;
|
||||
using node::NodeContext;
|
||||
using node::ReadBlockFromDisk;
|
||||
using node::SnapshotMetadata;
|
||||
@ -161,7 +160,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, TxVerbosity verbosity)
|
||||
UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, TxVerbosity verbosity)
|
||||
{
|
||||
UniValue result = blockheaderToJSON(tip, blockindex);
|
||||
|
||||
@ -180,7 +179,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn
|
||||
case TxVerbosity::SHOW_DETAILS:
|
||||
case TxVerbosity::SHOW_DETAILS_AND_PREVOUT:
|
||||
CBlockUndo blockUndo;
|
||||
const bool have_undo{WITH_LOCK(::cs_main, return !IsBlockPruned(blockindex) && UndoReadFromDisk(blockUndo, blockindex))};
|
||||
const bool have_undo{WITH_LOCK(::cs_main, return !blockman.IsBlockPruned(blockindex) && UndoReadFromDisk(blockUndo, blockindex))};
|
||||
|
||||
for (size_t i = 0; i < block.vtx.size(); ++i) {
|
||||
const CTransactionRef& tx = block.vtx.at(i);
|
||||
@ -565,11 +564,11 @@ static RPCHelpMan getblockheader()
|
||||
};
|
||||
}
|
||||
|
||||
static CBlock GetBlockChecked(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
static CBlock GetBlockChecked(BlockManager& blockman, const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
CBlock block;
|
||||
if (IsBlockPruned(pblockindex)) {
|
||||
if (blockman.IsBlockPruned(pblockindex)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
|
||||
}
|
||||
|
||||
@ -583,11 +582,11 @@ static CBlock GetBlockChecked(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_RE
|
||||
return block;
|
||||
}
|
||||
|
||||
static CBlockUndo GetUndoChecked(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
static CBlockUndo GetUndoChecked(BlockManager& blockman, const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
CBlockUndo blockUndo;
|
||||
if (IsBlockPruned(pblockindex)) {
|
||||
if (blockman.IsBlockPruned(pblockindex)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Undo data not available (pruned data)");
|
||||
}
|
||||
|
||||
@ -701,8 +700,8 @@ static RPCHelpMan getblock()
|
||||
CBlock block;
|
||||
const CBlockIndex* pblockindex;
|
||||
const CBlockIndex* tip;
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
LOCK(cs_main);
|
||||
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
tip = chainman.ActiveChain().Tip();
|
||||
@ -711,7 +710,7 @@ static RPCHelpMan getblock()
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
}
|
||||
|
||||
block = GetBlockChecked(pblockindex);
|
||||
block = GetBlockChecked(chainman.m_blockman, pblockindex);
|
||||
}
|
||||
|
||||
if (verbosity <= 0)
|
||||
@ -731,7 +730,7 @@ static RPCHelpMan getblock()
|
||||
tx_verbosity = TxVerbosity::SHOW_DETAILS_AND_PREVOUT;
|
||||
}
|
||||
|
||||
return blockToJSON(block, tip, pblockindex, tx_verbosity);
|
||||
return blockToJSON(chainman.m_blockman, block, tip, pblockindex, tx_verbosity);
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -1777,8 +1776,8 @@ static RPCHelpMan getblockstats()
|
||||
}
|
||||
}
|
||||
|
||||
const CBlock block = GetBlockChecked(pindex);
|
||||
const CBlockUndo blockUndo = GetUndoChecked(pindex);
|
||||
const CBlock block = GetBlockChecked(chainman.m_blockman, pindex);
|
||||
const CBlockUndo blockUndo = GetUndoChecked(chainman.m_blockman, pindex);
|
||||
|
||||
const bool do_all = stats.size() == 0; // Calculate everything if nothing selected (default)
|
||||
const bool do_mediantxsize = do_all || stats.count("mediantxsize") != 0;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <fs.h>
|
||||
#include <streams.h>
|
||||
#include <sync.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <any>
|
||||
#include <stdint.h>
|
||||
@ -39,7 +40,7 @@ double GetDifficulty(const CBlockIndex* blockindex);
|
||||
void RPCNotifyBlockChange(const CBlockIndex*);
|
||||
|
||||
/** Block description to JSON */
|
||||
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, TxVerbosity verbosity) LOCKS_EXCLUDED(cs_main);
|
||||
UniValue blockToJSON(node::BlockManager& blockman, const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, TxVerbosity verbosity) LOCKS_EXCLUDED(cs_main);
|
||||
|
||||
/** Block header to JSON */
|
||||
UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex) LOCKS_EXCLUDED(cs_main);
|
||||
|
@ -69,7 +69,6 @@ using node::CBlockIndexHeightOnlyComparator;
|
||||
using node::CBlockIndexWorkComparator;
|
||||
using node::CCoinsStats;
|
||||
using node::CoinStatsHashType;
|
||||
using node::fHavePruned;
|
||||
using node::fImporting;
|
||||
using node::fPruneMode;
|
||||
using node::fReindex;
|
||||
@ -2358,9 +2357,9 @@ bool CChainState::FlushStateToDisk(
|
||||
}
|
||||
if (!setFilesToPrune.empty()) {
|
||||
fFlushForPrune = true;
|
||||
if (!fHavePruned) {
|
||||
if (!m_blockman.fHavePruned) {
|
||||
m_blockman.m_block_tree_db->WriteFlag("prunedblockfiles", true);
|
||||
fHavePruned = true;
|
||||
m_blockman.fHavePruned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4127,7 +4126,7 @@ void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
|
||||
for (int b = 0; b < VERSIONBITS_NUM_BITS; b++) {
|
||||
warningcache[b].clear();
|
||||
}
|
||||
fHavePruned = false;
|
||||
chainman.m_blockman.fHavePruned = false;
|
||||
}
|
||||
|
||||
bool ChainstateManager::LoadBlockIndex()
|
||||
@ -4449,7 +4448,7 @@ void CChainState::CheckBlockIndex()
|
||||
// HAVE_DATA is only equivalent to nTx > 0 (or VALID_TRANSACTIONS) if no pruning has occurred.
|
||||
// Unless these indexes are assumed valid and pending block download on a
|
||||
// background chainstate.
|
||||
if (!fHavePruned && !pindex->IsAssumedValid()) {
|
||||
if (!m_blockman.fHavePruned && !pindex->IsAssumedValid()) {
|
||||
// If we've never pruned, then HAVE_DATA should be equivalent to nTx > 0
|
||||
assert(!(pindex->nStatus & BLOCK_HAVE_DATA) == (pindex->nTx == 0));
|
||||
assert(pindexFirstMissing == pindexFirstNeverProcessed);
|
||||
@ -4523,7 +4522,7 @@ void CChainState::CheckBlockIndex()
|
||||
if (pindexFirstMissing == nullptr) assert(!foundInUnlinked); // We aren't missing data for any parent -- cannot be in m_blocks_unlinked.
|
||||
if (pindex->pprev && (pindex->nStatus & BLOCK_HAVE_DATA) && pindexFirstNeverProcessed == nullptr && pindexFirstMissing != nullptr) {
|
||||
// We HAVE_DATA for this block, have received data for all parents at some point, but we're currently missing data for some parent.
|
||||
assert(fHavePruned); // We must have pruned.
|
||||
assert(m_blockman.fHavePruned); // We must have pruned.
|
||||
// This block may have entered m_blocks_unlinked if:
|
||||
// - it has a descendant that at some point had more work than the
|
||||
// tip, and
|
||||
|
Loading…
Reference in New Issue
Block a user