Skip to content

Commit 9333427

Browse files
committed
mempool: Introduce (still-unused) MemPoolLimits
They live as a CTxMemPool member. [META] These limits will be used in subsequent commits to replace calls to gArgs.
1 parent 716bb5f commit 9333427

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ BITCOIN_CORE_H = \
173173
kernel/checks.h \
174174
kernel/coinstats.h \
175175
kernel/context.h \
176+
kernel/mempool_limits.h \
176177
kernel/mempool_options.h \
177178
key.h \
178179
key_io.h \

src/kernel/mempool_limits.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

src/kernel/mempool_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
55
#define BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
66

7+
#include <kernel/mempool_limits.h>
8+
79
#include <chrono>
810
#include <cstdint>
911

@@ -29,6 +31,7 @@ struct MemPoolOptions {
2931
int check_ratio{0};
3032
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};
3133
std::chrono::seconds expiry{std::chrono::hours{DEFAULT_MEMPOOL_EXPIRY_HOURS}};
34+
MemPoolLimits limits{};
3235
};
3336
} // namespace kernel
3437

src/mempool_args.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,34 @@
44

55
#include <mempool_args.h>
66

7+
#include <kernel/mempool_limits.h>
78
#include <kernel/mempool_options.h>
89

910
#include <util/system.h>
1011

12+
using kernel::MemPoolLimits;
1113
using kernel::MemPoolOptions;
1214

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+
1328
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opts)
1429
{
1530
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
1631

1732
if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
1833

1934
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
35+
36+
ApplyArgsManOptions(argsman, mempool_opts.limits);
2037
}

src/mempool_args.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ namespace kernel {
1010
struct MemPoolOptions;
1111
};
1212

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+
*/
1319
void ApplyArgsManOptions(const ArgsManager& argsman, kernel::MemPoolOptions& mempool_opts);
1420

21+
1522
#endif // BITCOIN_MEMPOOL_ARGS_H

src/txmempool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ CTxMemPool::CTxMemPool(const Options& opts)
455455
: m_check_ratio{opts.check_ratio},
456456
minerPolicyEstimator{opts.estimator},
457457
m_max_size_bytes{opts.max_size_bytes},
458-
m_expiry{opts.expiry}
458+
m_expiry{opts.expiry},
459+
m_limits{opts.limits}
459460
{
460461
_clear(); //lock free clear
461462
}

src/txmempool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <utility>
1515
#include <vector>
1616

17+
#include <kernel/mempool_limits.h>
1718
#include <kernel/mempool_options.h>
1819

1920
#include <coins.h>
@@ -569,6 +570,10 @@ class CTxMemPool
569570
const int64_t m_max_size_bytes;
570571
const std::chrono::seconds m_expiry;
571572

573+
using Limits = kernel::MemPoolLimits;
574+
575+
const Limits m_limits;
576+
572577
/** Create a new CTxMemPool.
573578
* Sanity checks will be off by default for performance, because otherwise
574579
* accepting transactions becomes O(N^2) where N is the number of transactions

0 commit comments

Comments
 (0)