0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

Return optional error from ApplyArgsManOptions

Also pass in a (for now unused) reference to the params.

Both changes are needed for the next commit.
This commit is contained in:
MacroFake 2022-07-20 15:48:52 +02:00
parent 816ca01650
commit fa468bdfb6
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
5 changed files with 21 additions and 4 deletions

View file

@ -44,6 +44,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
" src/dbwrapper.cpp"\ " src/dbwrapper.cpp"\
" src/init"\ " src/init"\
" src/kernel"\ " src/kernel"\
" src/mempool_args.cpp"\
" src/node/chainstate.cpp"\ " src/node/chainstate.cpp"\
" src/policy/feerate.cpp"\ " src/policy/feerate.cpp"\
" src/policy/packages.cpp"\ " src/policy/packages.cpp"\

View file

@ -1418,7 +1418,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
.estimator = node.fee_estimator.get(), .estimator = node.fee_estimator.get(),
.check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0, .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); 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; int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40;

View file

@ -7,7 +7,13 @@
#include <kernel/mempool_limits.h> #include <kernel/mempool_limits.h>
#include <kernel/mempool_options.h> #include <kernel/mempool_options.h>
#include <chainparams.h>
#include <tinyformat.h>
#include <util/system.h> #include <util/system.h>
#include <util/translation.h>
#include <chrono>
#include <memory>
using kernel::MemPoolLimits; using kernel::MemPoolLimits;
using kernel::MemPoolOptions; 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); 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); mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);
ApplyArgsManOptions(argsman, mempool_opts.limits); ApplyArgsManOptions(argsman, mempool_opts.limits);
return std::nullopt;
} }

View file

@ -5,18 +5,23 @@
#ifndef BITCOIN_MEMPOOL_ARGS_H #ifndef BITCOIN_MEMPOOL_ARGS_H
#define BITCOIN_MEMPOOL_ARGS_H #define BITCOIN_MEMPOOL_ARGS_H
#include <optional>
class ArgsManager; class ArgsManager;
class CChainParams;
struct bilingual_str;
namespace kernel { namespace kernel {
struct MemPoolOptions; struct MemPoolOptions;
}; };
/** /**
* Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts. * 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] argsman The ArgsManager in which to check set options.
* @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman. * @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 #endif // BITCOIN_MEMPOOL_ARGS_H

View file

@ -160,7 +160,8 @@ CTxMemPool::Options MemPoolOptionsForTest(const NodeContext& node)
// chainparams.DefaultConsistencyChecks for tests // chainparams.DefaultConsistencyChecks for tests
.check_ratio = 1, .check_ratio = 1,
}; };
ApplyArgsManOptions(*node.args, mempool_opts); const auto err{ApplyArgsManOptions(*node.args, ::Params(), mempool_opts)};
Assert(!err);
return mempool_opts; return mempool_opts;
} }