Skip to content

Commit fae71fe

Browse files
author
MarcoFalke
committed
Add BlockManager::GetPruneTarget()
1 parent fa0f043 commit fae71fe

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/init.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,8 +1617,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16171617

16181618
// On first startup, warn on low block storage space
16191619
if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
1620-
uint64_t additional_bytes_needed = fPruneMode ? nPruneTarget
1621-
: chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024;
1620+
uint64_t additional_bytes_needed{
1621+
fPruneMode ?
1622+
chainman.m_blockman.GetPruneTarget() :
1623+
chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024};
16221624

16231625
if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
16241626
InitWarning(strprintf(_(

src/node/blockstorage.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ extern std::atomic_bool fReindex;
5151
/** Pruning-related variables and constants */
5252
/** True if we're running in -prune mode. */
5353
extern bool fPruneMode;
54-
/** Number of bytes of block files that we're trying to stay below. */
5554
extern uint64_t nPruneTarget;
5655

5756
// Because validation code takes pointers to the map's CBlockIndex objects, if
@@ -176,6 +175,9 @@ class BlockManager
176175
/** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
177176
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
178177

178+
/** Attempt to stay below this number of bytes of block files. */
179+
[[nodiscard]] uint64_t GetPruneTarget() const { return nPruneTarget; }
180+
179181
[[nodiscard]] bool LoadingBlocks() const
180182
{
181183
return fImporting || fReindex;

src/node/chainstate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
4444
if (chainman.MinimumChainWork() < UintToArith256(chainman.GetConsensus().nMinimumChainWork)) {
4545
LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainman.GetConsensus().nMinimumChainWork.GetHex());
4646
}
47-
if (nPruneTarget == std::numeric_limits<uint64_t>::max()) {
47+
if (chainman.m_blockman.GetPruneTarget() == std::numeric_limits<uint64_t>::max()) {
4848
LogPrintf("Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
49-
} else if (nPruneTarget) {
50-
LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
49+
} else if (chainman.m_blockman.GetPruneTarget()) {
50+
LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", chainman.m_blockman.GetPruneTarget() / 1024 / 1024);
5151
}
5252

5353
LOCK(cs_main);

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ RPCHelpMan getblockchaininfo()
12731273
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
12741274
obj.pushKV("automatic_pruning", automatic_pruning);
12751275
if (automatic_pruning) {
1276-
obj.pushKV("prune_target_size", node::nPruneTarget);
1276+
obj.pushKV("prune_target_size", chainman.m_blockman.GetPruneTarget());
12771277
}
12781278
}
12791279

0 commit comments

Comments
 (0)