diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-20 15:48:52 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-08-02 15:21:50 +0200 |
commit | fa468bdfb62dec286cb977db78d3e47b64dafeba (patch) | |
tree | cb9aef62e507e26226dc7d04d06a3f7b83f497ea | |
parent | 816ca01650f4cc66a61ac2f9b0f8b74cd9cd0cf8 (diff) |
Return optional error from ApplyArgsManOptions
Also pass in a (for now unused) reference to the params.
Both changes are needed for the next commit.
-rwxr-xr-x | ci/test/06_script_b.sh | 1 | ||||
-rw-r--r-- | src/init.cpp | 4 | ||||
-rw-r--r-- | src/mempool_args.cpp | 10 | ||||
-rw-r--r-- | src/mempool_args.h | 7 | ||||
-rw-r--r-- | src/test/util/setup_common.cpp | 3 |
5 files changed, 21 insertions, 4 deletions
diff --git a/ci/test/06_script_b.sh b/ci/test/06_script_b.sh index 1220b15d5a..978830b7e2 100755 --- a/ci/test/06_script_b.sh +++ b/ci/test/06_script_b.sh @@ -44,6 +44,7 @@ if [ "${RUN_TIDY}" = "true" ]; then " src/dbwrapper.cpp"\ " src/init"\ " src/kernel"\ + " src/mempool_args.cpp"\ " src/node/chainstate.cpp"\ " src/policy/feerate.cpp"\ " src/policy/packages.cpp"\ diff --git a/src/init.cpp b/src/init.cpp index a94bbe6460..9a3c70abbd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1418,7 +1418,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) .estimator = node.fee_estimator.get(), .check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0, }; - ApplyArgsManOptions(args, mempool_opts); + if (const auto err{ApplyArgsManOptions(args, chainparams, mempool_opts)}) { + return InitError(*err); + } mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000); int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40; diff --git a/src/mempool_args.cpp b/src/mempool_args.cpp index 77caa127e9..da0fb62262 100644 --- a/src/mempool_args.cpp +++ b/src/mempool_args.cpp @@ -7,7 +7,13 @@ #include <kernel/mempool_limits.h> #include <kernel/mempool_options.h> +#include <chainparams.h> +#include <tinyformat.h> #include <util/system.h> +#include <util/translation.h> + +#include <chrono> +#include <memory> using kernel::MemPoolLimits; using kernel::MemPoolOptions; @@ -25,7 +31,7 @@ void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limi } } -void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opts) +std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts) { mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio); @@ -36,4 +42,6 @@ void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opt mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf); ApplyArgsManOptions(argsman, mempool_opts.limits); + + return std::nullopt; } diff --git a/src/mempool_args.h b/src/mempool_args.h index 9a4abe6618..72d202cca2 100644 --- a/src/mempool_args.h +++ b/src/mempool_args.h @@ -5,18 +5,23 @@ #ifndef BITCOIN_MEMPOOL_ARGS_H #define BITCOIN_MEMPOOL_ARGS_H +#include <optional> + class ArgsManager; +class CChainParams; +struct bilingual_str; namespace kernel { struct MemPoolOptions; }; /** * Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts. + * Returns an error if one was encountered. * * @param[in] argsman The ArgsManager in which to check set options. * @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman. */ -void ApplyArgsManOptions(const ArgsManager& argsman, kernel::MemPoolOptions& mempool_opts); +[[nodiscard]] std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, kernel::MemPoolOptions& mempool_opts); #endif // BITCOIN_MEMPOOL_ARGS_H diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 67984721a3..f5076c043b 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -160,7 +160,8 @@ CTxMemPool::Options MemPoolOptionsForTest(const NodeContext& node) // chainparams.DefaultConsistencyChecks for tests .check_ratio = 1, }; - ApplyArgsManOptions(*node.args, mempool_opts); + const auto err{ApplyArgsManOptions(*node.args, ::Params(), mempool_opts)}; + Assert(!err); return mempool_opts; } |