File tree Expand file tree Collapse file tree 7 files changed +61
-1
lines changed Expand file tree Collapse file tree 7 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ BITCOIN_CORE_H = \
173
173
kernel/checks.h \
174
174
kernel/coinstats.h \
175
175
kernel/context.h \
176
+ kernel/mempool_limits.h \
176
177
kernel/mempool_options.h \
177
178
key.h \
178
179
key_io.h \
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2022 The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+ #ifndef BITCOIN_KERNEL_MEMPOOL_LIMITS_H
5
+ #define BITCOIN_KERNEL_MEMPOOL_LIMITS_H
6
+
7
+ #include < policy/policy.h>
8
+
9
+ #include < cstdint>
10
+
11
+ namespace kernel {
12
+ /* *
13
+ * Options struct containing limit options for a CTxMemPool. Default constructor
14
+ * populates the struct with sane default values which can be modified.
15
+ *
16
+ * Most of the time, this struct should be referenced as CTxMemPool::Limits.
17
+ */
18
+ struct MemPoolLimits {
19
+ int64_t ancestor_count{DEFAULT_ANCESTOR_LIMIT};
20
+ int64_t ancestor_size_vbytes{DEFAULT_ANCESTOR_SIZE_LIMIT_KVB * 1'000 };
21
+ int64_t descendant_count{DEFAULT_DESCENDANT_LIMIT};
22
+ int64_t descendant_size_vbytes{DEFAULT_DESCENDANT_SIZE_LIMIT_KVB * 1'000 };
23
+ };
24
+ } // namespace kernel
25
+
26
+ #endif // BITCOIN_KERNEL_MEMPOOL_LIMITS_H
Original file line number Diff line number Diff line change 4
4
#ifndef BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
5
5
#define BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
6
6
7
+ #include < kernel/mempool_limits.h>
8
+
7
9
#include < chrono>
8
10
#include < cstdint>
9
11
@@ -29,6 +31,7 @@ struct MemPoolOptions {
29
31
int check_ratio{0 };
30
32
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000 };
31
33
std::chrono::seconds expiry{std::chrono::hours{DEFAULT_MEMPOOL_EXPIRY_HOURS}};
34
+ MemPoolLimits limits{};
32
35
};
33
36
} // namespace kernel
34
37
Original file line number Diff line number Diff line change 4
4
5
5
#include < mempool_args.h>
6
6
7
+ #include < kernel/mempool_limits.h>
7
8
#include < kernel/mempool_options.h>
8
9
9
10
#include < util/system.h>
10
11
12
+ using kernel::MemPoolLimits;
11
13
using kernel::MemPoolOptions;
12
14
15
+ namespace {
16
+ void ApplyArgsManOptions (const ArgsManager& argsman, MemPoolLimits& mempool_limits)
17
+ {
18
+ mempool_limits.ancestor_count = argsman.GetIntArg (" -limitancestorcount" , mempool_limits.ancestor_count );
19
+
20
+ if (auto vkb = argsman.GetIntArg (" -limitancestorsize" )) mempool_limits.ancestor_size_vbytes = *vkb * 1'000 ;
21
+
22
+ mempool_limits.descendant_count = argsman.GetIntArg (" -limitdescendantcount" , mempool_limits.descendant_count );
23
+
24
+ if (auto vkb = argsman.GetIntArg (" -limitdescendantsize" )) mempool_limits.descendant_size_vbytes = *vkb * 1'000 ;
25
+ }
26
+ }
27
+
13
28
void ApplyArgsManOptions (const ArgsManager& argsman, MemPoolOptions& mempool_opts)
14
29
{
15
30
mempool_opts.check_ratio = argsman.GetIntArg (" -checkmempool" , mempool_opts.check_ratio );
16
31
17
32
if (auto mb = argsman.GetIntArg (" -maxmempool" )) mempool_opts.max_size_bytes = *mb * 1'000'000 ;
18
33
19
34
if (auto hours = argsman.GetIntArg (" -mempoolexpiry" )) mempool_opts.expiry = std::chrono::hours{*hours};
35
+
36
+ ApplyArgsManOptions (argsman, mempool_opts.limits );
20
37
}
Original file line number Diff line number Diff line change @@ -10,6 +10,13 @@ namespace kernel {
10
10
struct MemPoolOptions ;
11
11
};
12
12
13
+ /* *
14
+ * Overlay the options set in \p argsman on top of corresponding members in \p mempool_opts.
15
+ *
16
+ * @param[in] argsman The ArgsManager in which to check set options.
17
+ * @param[in,out] mempool_opts The MemPoolOptions to modify according to \p argsman.
18
+ */
13
19
void ApplyArgsManOptions (const ArgsManager& argsman, kernel::MemPoolOptions& mempool_opts);
14
20
21
+
15
22
#endif // BITCOIN_MEMPOOL_ARGS_H
Original file line number Diff line number Diff line change @@ -455,7 +455,8 @@ CTxMemPool::CTxMemPool(const Options& opts)
455
455
: m_check_ratio{opts.check_ratio },
456
456
minerPolicyEstimator{opts.estimator },
457
457
m_max_size_bytes{opts.max_size_bytes },
458
- m_expiry{opts.expiry }
458
+ m_expiry{opts.expiry },
459
+ m_limits{opts.limits }
459
460
{
460
461
_clear (); // lock free clear
461
462
}
Original file line number Diff line number Diff line change 14
14
#include < utility>
15
15
#include < vector>
16
16
17
+ #include < kernel/mempool_limits.h>
17
18
#include < kernel/mempool_options.h>
18
19
19
20
#include < coins.h>
@@ -569,6 +570,10 @@ class CTxMemPool
569
570
const int64_t m_max_size_bytes;
570
571
const std::chrono::seconds m_expiry;
571
572
573
+ using Limits = kernel::MemPoolLimits;
574
+
575
+ const Limits m_limits;
576
+
572
577
/* * Create a new CTxMemPool.
573
578
* Sanity checks will be off by default for performance, because otherwise
574
579
* accepting transactions becomes O(N^2) where N is the number of transactions
You can’t perform that action at this time.
0 commit comments