mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-17 21:32:00 +01:00
Merge d4a3abf6d430e12f54241a6191a9226fb0d31a65 into 5f4422d68dc3530c353af1f87499de1c864b60ad
This commit is contained in:
commit
6567b9e977
@ -508,6 +508,9 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
|
|||||||
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex. "
|
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex. "
|
||||||
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
|
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
|
||||||
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
|
argsman.AddArg("-pruneduringinit", "Temporarily adjusts the -prune setting until initial sync completes."
|
||||||
|
" Ignored if pruning is disabled."
|
||||||
|
" (default: -1 = same value as -prune)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-reindex", "If enabled, wipe chain state and block index, and rebuild them from blk*.dat files on disk. Also wipe and rebuild other optional indexes that are active. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-reindex", "If enabled, wipe chain state and block index, and rebuild them from blk*.dat files on disk. Also wipe and rebuild other optional indexes that are active. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-reindex-chainstate", "If enabled, wipe chain state, and rebuild it from blk*.dat files on disk. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-reindex-chainstate", "If enabled, wipe chain state, and rebuild it from blk*.dat files on disk. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-settings=<file>", strprintf("Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME, BITCOIN_SETTINGS_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-settings=<file>", strprintf("Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME, BITCOIN_SETTINGS_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
|
@ -25,6 +25,7 @@ struct BlockManagerOpts {
|
|||||||
const CChainParams& chainparams;
|
const CChainParams& chainparams;
|
||||||
bool use_xor{DEFAULT_XOR_BLOCKSDIR};
|
bool use_xor{DEFAULT_XOR_BLOCKSDIR};
|
||||||
uint64_t prune_target{0};
|
uint64_t prune_target{0};
|
||||||
|
int64_t prune_target_during_init{-1};
|
||||||
bool fast_prune{false};
|
bool fast_prune{false};
|
||||||
const fs::path blocks_dir;
|
const fs::path blocks_dir;
|
||||||
Notifications& notifications;
|
Notifications& notifications;
|
||||||
|
@ -12,26 +12,50 @@
|
|||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
util::Result<uint64_t> ParsePruneOption(const int64_t nPruneArg, const std::string_view opt_name)
|
||||||
|
{
|
||||||
|
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
|
||||||
|
if (nPruneArg < 0) {
|
||||||
|
return util::Error{strprintf(_("%s cannot be configured with a negative value."), opt_name)};
|
||||||
|
} else if (nPruneArg == 0) { // pruning disabled
|
||||||
|
return 0;
|
||||||
|
} else if (nPruneArg == 1) { // manual pruning: -prune=1
|
||||||
|
return BlockManager::PRUNE_TARGET_MANUAL;
|
||||||
|
}
|
||||||
|
const uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
|
||||||
|
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
|
||||||
|
return util::Error{strprintf(_("%s configured below the minimum of %d MiB. Please use a higher number."), opt_name, MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)};
|
||||||
|
}
|
||||||
|
return nPruneTarget;
|
||||||
|
}
|
||||||
|
|
||||||
util::Result<void> ApplyArgsManOptions(const ArgsManager& args, BlockManager::Options& opts)
|
util::Result<void> ApplyArgsManOptions(const ArgsManager& args, BlockManager::Options& opts)
|
||||||
{
|
{
|
||||||
if (auto value{args.GetBoolArg("-blocksxor")}) opts.use_xor = *value;
|
if (auto value{args.GetBoolArg("-blocksxor")}) opts.use_xor = *value;
|
||||||
|
|
||||||
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
|
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
|
||||||
int64_t nPruneArg{args.GetIntArg("-prune", opts.prune_target)};
|
int64_t nPruneArg{args.GetIntArg("-prune", opts.prune_target)};
|
||||||
if (nPruneArg < 0) {
|
if (const auto prune_parsed = ParsePruneOption(nPruneArg, "Prune")) {
|
||||||
return util::Error{_("Prune cannot be configured with a negative value.")};
|
opts.prune_target = *prune_parsed;
|
||||||
|
} else {
|
||||||
|
return util::Error{util::ErrorString(prune_parsed)};
|
||||||
}
|
}
|
||||||
uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
|
|
||||||
if (nPruneArg == 1) { // manual pruning: -prune=1
|
if (const auto prune_during_init{args.GetIntArg("-pruneduringinit")}) {
|
||||||
nPruneTarget = BlockManager::PRUNE_TARGET_MANUAL;
|
if (*prune_during_init == -1) {
|
||||||
} else if (nPruneTarget) {
|
opts.prune_target_during_init = -1;
|
||||||
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
|
} else if (const auto prune_parsed = ParsePruneOption(*prune_during_init, "-pruneduringinit")) {
|
||||||
return util::Error{strprintf(_("Prune configured below the minimum of %d MiB. Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)};
|
// NOTE: PRUNE_TARGET_MANUAL is >int64 max
|
||||||
|
opts.prune_target_during_init = std::min(std::numeric_limits<int64_t>::max(), (int64_t)*prune_parsed);
|
||||||
|
} else {
|
||||||
|
return util::Error{util::ErrorString(prune_parsed)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts.prune_target = nPruneTarget;
|
|
||||||
|
|
||||||
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
|
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
|
||||||
|
|
||||||
|
@ -299,6 +299,26 @@ void BlockManager::FindFilesToPruneManual(
|
|||||||
chain.GetRole(), last_block_can_prune, count);
|
chain.GetRole(), last_block_can_prune, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t BlockManager::GetPruneTargetForChainstate(const Chainstate& chain, ChainstateManager& chainman) const
|
||||||
|
{
|
||||||
|
const auto number_of_chainstates{chainman.GetAll().size()};
|
||||||
|
const uint64_t min_overall_target{MIN_DISK_SPACE_FOR_BLOCK_FILES * number_of_chainstates};
|
||||||
|
auto target = std::max(min_overall_target, GetPruneTarget());
|
||||||
|
uint64_t target_boost{0};
|
||||||
|
if (m_opts.prune_target_during_init > -1 && chainman.IsInitialBlockDownload()) {
|
||||||
|
if ((uint64_t)m_opts.prune_target_during_init <= target) {
|
||||||
|
target = std::max(min_overall_target, (uint64_t)m_opts.prune_target_during_init);
|
||||||
|
} else if (chain.GetRole() != ChainstateRole::ASSUMEDVALID) {
|
||||||
|
// Only the background/normal gets the benefit
|
||||||
|
// NOTE: This assumes only one such chainstate exists
|
||||||
|
target_boost = m_opts.prune_target_during_init - target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Distribute our -prune budget over all chainstates.
|
||||||
|
target = (target / number_of_chainstates) + target_boost;
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
void BlockManager::FindFilesToPrune(
|
void BlockManager::FindFilesToPrune(
|
||||||
std::set<int>& setFilesToPrune,
|
std::set<int>& setFilesToPrune,
|
||||||
int last_prune,
|
int last_prune,
|
||||||
@ -306,9 +326,7 @@ void BlockManager::FindFilesToPrune(
|
|||||||
ChainstateManager& chainman)
|
ChainstateManager& chainman)
|
||||||
{
|
{
|
||||||
LOCK2(cs_main, cs_LastBlockFile);
|
LOCK2(cs_main, cs_LastBlockFile);
|
||||||
// Distribute our -prune budget over all chainstates.
|
const auto target{GetPruneTargetForChainstate(chain, chainman)};
|
||||||
const auto target = std::max(
|
|
||||||
MIN_DISK_SPACE_FOR_BLOCK_FILES, GetPruneTarget() / chainman.GetAll().size());
|
|
||||||
const uint64_t target_sync_height = chainman.m_best_header->nHeight;
|
const uint64_t target_sync_height = chainman.m_best_header->nHeight;
|
||||||
|
|
||||||
if (chain.m_chain.Height() < 0 || target == 0) {
|
if (chain.m_chain.Height() < 0 || target == 0) {
|
||||||
|
@ -350,6 +350,7 @@ public:
|
|||||||
|
|
||||||
/** Attempt to stay below this number of bytes of block files. */
|
/** Attempt to stay below this number of bytes of block files. */
|
||||||
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }
|
[[nodiscard]] uint64_t GetPruneTarget() const { return m_opts.prune_target; }
|
||||||
|
[[nodiscard]] uint64_t GetPruneTargetForChainstate(const Chainstate& chain, ChainstateManager& chainman) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
static constexpr auto PRUNE_TARGET_MANUAL{std::numeric_limits<uint64_t>::max()};
|
static constexpr auto PRUNE_TARGET_MANUAL{std::numeric_limits<uint64_t>::max()};
|
||||||
|
|
||||||
[[nodiscard]] bool LoadingBlocks() const { return m_importing || !m_blockfiles_indexed; }
|
[[nodiscard]] bool LoadingBlocks() const { return m_importing || !m_blockfiles_indexed; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user