2023-01-03 13:12:45 +01:00
|
|
|
// Copyright (c) 2023 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <node/blockmanager_args.h>
|
|
|
|
|
2023-03-23 12:23:29 +01:00
|
|
|
#include <common/args.h>
|
2023-03-16 11:02:24 +01:00
|
|
|
#include <node/blockstorage.h>
|
|
|
|
#include <tinyformat.h>
|
2022-09-01 15:35:23 -04:00
|
|
|
#include <util/result.h>
|
2023-03-16 11:02:24 +01:00
|
|
|
#include <util/translation.h>
|
2023-01-03 13:12:45 +01:00
|
|
|
#include <validation.h>
|
|
|
|
|
2023-03-16 11:02:24 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
2023-01-03 13:12:45 +01:00
|
|
|
namespace node {
|
2022-09-01 15:35:23 -04:00
|
|
|
util::Result<void> ApplyArgsManOptions(const ArgsManager& args, BlockManager::Options& opts)
|
2023-01-03 13:12:45 +01:00
|
|
|
{
|
|
|
|
// 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)};
|
|
|
|
if (nPruneArg < 0) {
|
2022-09-01 15:35:23 -04:00
|
|
|
return util::Error{_("Prune cannot be configured with a negative value.")};
|
2023-01-03 13:12:45 +01:00
|
|
|
}
|
|
|
|
uint64_t nPruneTarget{uint64_t(nPruneArg) * 1024 * 1024};
|
|
|
|
if (nPruneArg == 1) { // manual pruning: -prune=1
|
2023-03-15 16:10:24 +01:00
|
|
|
nPruneTarget = BlockManager::PRUNE_TARGET_MANUAL;
|
2023-01-03 13:12:45 +01:00
|
|
|
} else if (nPruneTarget) {
|
|
|
|
if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
|
2022-09-01 15:35:23 -04:00
|
|
|
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)};
|
2023-01-03 13:12:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
opts.prune_target = nPruneTarget;
|
|
|
|
|
2023-02-18 12:57:39 +01:00
|
|
|
if (auto value{args.GetBoolArg("-fastprune")}) opts.fast_prune = *value;
|
|
|
|
|
2022-09-01 15:35:23 -04:00
|
|
|
return {};
|
2023-01-03 13:12:45 +01:00
|
|
|
}
|
|
|
|
} // namespace node
|