A few issues:
This check uses the knowledge that the special magic constant std::numeric_limits<uint64_t>::max() is returned by GetPruneTarget() and that in such cases additional_bytes does not make sense. That's not for CheckDiskSpace() to know - the caller should choose a better additional_bytes when calling CheckDiskSpace().
This magic constant is used in two other places - when setting nPruneTarget and in LoadChainstate(). It is better to give it a name instead of repeating it for a 3rd time (e.g. PRUNE_TARGET_UNLIMITED);
In the case of prune=1 I think we should use additional_bytes=chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024, not 0.
To address all three what about introducing
BlockManager::IsPruneModeAutomatic()
{
return fPruneMode && nPruneTarget != PRUNE_TARGET_UNLIMITED;
}
and then
diff --git i/src/init.cpp w/src/init.cpp
index f296c16208..3336b66c06 100644
--- i/src/init.cpp
+++ w/src/init.cpp
@@ -1628,13 +1628,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
int chain_active_height = WITH_LOCK(cs_main, return chainman.ActiveChain().Height());
// On first startup, warn on low block storage space
if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
uint64_t additional_bytes_needed{
- chainman.m_blockman.IsPruneMode() ?
+ chainman.m_blockman.IsPruneModeAutomatic() ?
chainman.m_blockman.GetPruneTarget() :
chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024};
if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
InitWarning(strprintf(_(
"Disk space for %s may not accommodate the block files. " \
diff --git i/src/node/chainstate.cpp w/src/node/chainstate.cpp
index 4741c4c421..3dc24c438c 100644
--- i/src/node/chainstate.cpp
+++ w/src/node/chainstate.cpp
@@ -41,13 +41,13 @@ ChainstateLoadResult LoadChainstate(ChainstateManager& chainman, const CacheSize
LogPrintf("Validating signatures for all blocks.\n");
}
LogPrintf("Setting nMinimumChainWork=%s\n", chainman.MinimumChainWork().GetHex());
if (chainman.MinimumChainWork() < UintToArith256(chainman.GetConsensus().nMinimumChainWork)) {
LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainman.GetConsensus().nMinimumChainWork.GetHex());
}
- if (chainman.m_blockman.GetPruneTarget() == std::numeric_limits<uint64_t>::max()) {
+ if (!chainman.m_blockman.IsPruneModeAutomatic()) {
LogPrintf("Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
} else if (chainman.m_blockman.GetPruneTarget()) {
LogPrintf("Prune configured to target %u MiB on disk for block and undo files.\n", chainman.m_blockman.GetPruneTarget() / 1024 / 1024);
}
LOCK(cs_main);
diff --git i/src/rpc/blockchain.cpp w/src/rpc/blockchain.cpp
index 8bee066ab8..c20b312e3d 100644
--- i/src/rpc/blockchain.cpp
+++ w/src/rpc/blockchain.cpp
@@ -1269,13 +1269,13 @@ RPCHelpMan getblockchaininfo()
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
obj.pushKV("pruned", chainman.m_blockman.IsPruneMode());
if (chainman.m_blockman.IsPruneMode()) {
obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(tip)->nHeight);
// if 0, execution bypasses the whole if block.
- bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
+ const bool automatic_pruning{chainman.m_blockman.IsPruneModeAutomatic()};
obj.pushKV("automatic_pruning", automatic_pruning);
if (automatic_pruning) {
obj.pushKV("prune_target_size", chainman.m_blockman.GetPruneTarget());
}
}