diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 439239962ab..b5f8cd1f4e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -232,6 +232,7 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL node/mempool_persist.cpp node/mempool_persist_args.cpp node/miner.cpp + node/mining_args.cpp node/mini_miner.cpp node/minisketchwrapper.cpp node/peerman_args.cpp diff --git a/src/init.cpp b/src/init.cpp index c53e5ed634c..adf94665f59 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -124,7 +125,6 @@ #include #endif -using common::AmountErrMsg; using common::InvalidPortErrMsg; using common::ResolveErrMsg; @@ -1074,27 +1074,9 @@ bool AppInitParameterInteraction(const ArgsManager& args) return InitError(Untranslated("peertimeout must be a positive integer.")); } - if (const auto arg{args.GetArg("-blockmintxfee")}) { - if (!ParseMoney(*arg)) { - return InitError(AmountErrMsg("blockmintxfee", *arg)); - } - } - - { - const auto max_block_weight = args.GetIntArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT); - if (max_block_weight > MAX_BLOCK_WEIGHT) { - return InitError(strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT)); - } - } - - { - const auto block_reserved_weight = args.GetIntArg("-blockreservedweight", DEFAULT_BLOCK_RESERVED_WEIGHT); - if (block_reserved_weight > MAX_BLOCK_WEIGHT) { - return InitError(strprintf(_("Specified -blockreservedweight (%d) exceeds consensus maximum block weight (%d)"), block_reserved_weight, MAX_BLOCK_WEIGHT)); - } - if (block_reserved_weight < MINIMUM_BLOCK_RESERVED_WEIGHT) { - return InitError(strprintf(_("Specified -blockreservedweight (%d) is lower than minimum safety value of (%d)"), block_reserved_weight, MINIMUM_BLOCK_RESERVED_WEIGHT)); - } + auto mining_result{node::ReadMiningArgs(args)}; + if (!mining_result) { + return InitError(util::ErrorString(mining_result)); } nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp); diff --git a/src/node/mining_args.cpp b/src/node/mining_args.cpp new file mode 100644 index 00000000000..ece422a808e --- /dev/null +++ b/src/node/mining_args.cpp @@ -0,0 +1,47 @@ +// Copyright (c) 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 + +#include +#include +#include +#include +#include +#include +#include + +#include + +using common::AmountErrMsg; +using util::Error; +using util::Result; + +namespace node { + +Result ReadMiningArgs(const ArgsManager& args) +{ + if (const auto arg{args.GetArg("-blockmintxfee")}) { + if (!ParseMoney(*arg)) { + return Error{AmountErrMsg("blockmintxfee", *arg)}; + } + } + + const uint64_t max_block_weight{args.GetArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT)}; + if (max_block_weight > MAX_BLOCK_WEIGHT) { + return Error{strprintf(_("Specified -blockmaxweight (%d) exceeds consensus maximum block weight (%d)"), max_block_weight, MAX_BLOCK_WEIGHT)}; + } + + const uint64_t block_reserved_weight{args.GetArg("-blockreservedweight", DEFAULT_BLOCK_RESERVED_WEIGHT)}; + if (block_reserved_weight > MAX_BLOCK_WEIGHT) { + return Error{strprintf(_("Specified -blockreservedweight (%d) exceeds consensus maximum block weight (%d)"), block_reserved_weight, MAX_BLOCK_WEIGHT)}; + } + if (block_reserved_weight < MINIMUM_BLOCK_RESERVED_WEIGHT) { + return Error{strprintf(_("Specified -blockreservedweight (%d) is lower than minimum safety value of (%d)"), block_reserved_weight, MINIMUM_BLOCK_RESERVED_WEIGHT)}; + } + + return {}; +} + +} // namespace node diff --git a/src/node/mining_args.h b/src/node/mining_args.h new file mode 100644 index 00000000000..01e695ee82c --- /dev/null +++ b/src/node/mining_args.h @@ -0,0 +1,18 @@ +// Copyright (c) The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_NODE_MINING_ARGS_H +#define BITCOIN_NODE_MINING_ARGS_H + +#include + +class ArgsManager; + +namespace node { + +[[nodiscard]] util::Result ReadMiningArgs(const ArgsManager& args); + +} // namespace node + +#endif // BITCOIN_NODE_MINING_ARGS_H