Bitcoin Core  28.1.0
P2P Digital Currency
blockmanager_args.cpp
Go to the documentation of this file.
1 // Copyright (c) 2023 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 
7 #include <common/args.h>
8 #include <node/blockstorage.h>
9 #include <tinyformat.h>
10 #include <util/result.h>
11 #include <util/translation.h>
12 #include <validation.h>
13 
14 #include <cstdint>
15 
16 namespace node {
18 {
19  if (auto value{args.GetBoolArg("-blocksxor")}) opts.use_xor = *value;
20  // block pruning; get the amount of disk space (in MiB) to allot for block & undo files
21  int64_t nPruneArg{args.GetIntArg("-prune", opts.prune_target)};
22  if (nPruneArg < 0) {
23  return util::Error{_("Prune cannot be configured with a negative value.")};
24  }
25  uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
26  if (nPruneArg == 1) { // manual pruning: -prune=1
27  nPruneTarget = BlockManager::PRUNE_TARGET_MANUAL;
28  } else if (nPruneTarget) {
29  if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
30  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)};
31  }
32  }
33  opts.prune_target = nPruneTarget;
34 
35  if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
36 
37  return {};
38 }
39 } // namespace node
static constexpr auto PRUNE_TARGET_MANUAL
Definition: blockstorage.h:359
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1161
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: args.cpp:506
util::Result< void > ApplyArgsManOptions(const ArgsManager &args, BlockManager::Options &opts)
An options struct for BlockManager, more ergonomically referred to as BlockManager::Options due to th...
ArgsManager & args
Definition: bitcoind.cpp:270
Definition: messages.h:20
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:481
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:79
bilingual_str _(ConstevalStringLiteral str)
Translation function.
Definition: translation.h:80