Skip to content

Commit fa468bd

Browse files
author
MacroFake
committed
Return optional error from ApplyArgsManOptions
Also pass in a (for now unused) reference to the params. Both changes are needed for the next commit.
1 parent 816ca01 commit fa468bd

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

ci/test/06_script_b.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
4444
" src/dbwrapper.cpp"\
4545
" src/init"\
4646
" src/kernel"\
47+
" src/mempool_args.cpp"\
4748
" src/node/chainstate.cpp"\
4849
" src/policy/feerate.cpp"\
4950
" src/policy/packages.cpp"\

src/init.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14181418
.estimator = node.fee_estimator.get(),
14191419
.check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0,
14201420
};
1421-
ApplyArgsManOptions(args, mempool_opts);
1421+
if (const auto err{ApplyArgsManOptions(args, chainparams, mempool_opts)}) {
1422+
return InitError(*err);
1423+
}
14221424
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
14231425

14241426
int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40;

src/mempool_args.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
#include <kernel/mempool_limits.h>
88
#include <kernel/mempool_options.h>
99

10+
#include <chainparams.h>
11+
#include <tinyformat.h>
1012
#include <util/system.h>
13+
#include <util/translation.h>
14+
15+
#include <chrono>
16+
#include <memory>
1117

1218
using kernel::MemPoolLimits;
1319
using kernel::MemPoolOptions;
@@ -25,7 +31,7 @@ void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limi
2531
}
2632
}
2733

28-
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opts)
34+
std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, MemPoolOptions& mempool_opts)
2935
{
3036
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
3137

@@ -36,4 +42,6 @@ void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opt
3642
mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);
3743

3844
ApplyArgsManOptions(argsman, mempool_opts.limits);
45+
46+
return std::nullopt;
3947
}

src/mempool_args.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
#ifndef BITCOIN_MEMPOOL_ARGS_H
66
#define BITCOIN_MEMPOOL_ARGS_H
77

8+
#include <optional>
9+
810
class ArgsManager;
11+
class CChainParams;
12+
struct bilingual_str;
913
namespace kernel {
1014
struct MemPoolOptions;
1115
};
1216

1317
/**
1418
* Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts.
19+
* Returns an error if one was encountered.
1520
*
1621
* @param[in] argsman The ArgsManager in which to check set options.
1722
* @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman.
1823
*/
19-
void ApplyArgsManOptions(const ArgsManager& argsman, kernel::MemPoolOptions& mempool_opts);
24+
[[nodiscard]] std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, const CChainParams& chainparams, kernel::MemPoolOptions& mempool_opts);
2025

2126

2227
#endif // BITCOIN_MEMPOOL_ARGS_H

src/test/util/setup_common.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ CTxMemPool::Options MemPoolOptionsForTest(const NodeContext& node)
160160
// chainparams.DefaultConsistencyChecks for tests
161161
.check_ratio = 1,
162162
};
163-
ApplyArgsManOptions(*node.args, mempool_opts);
163+
const auto err{ApplyArgsManOptions(*node.args, ::Params(), mempool_opts)};
164+
Assert(!err);
164165
return mempool_opts;
165166
}
166167

0 commit comments

Comments
 (0)