HomePhabricator

pool: Add and use MemPoolOptions, ApplyArgsManOptions

Description

pool: Add and use MemPoolOptions, ApplyArgsManOptions

Summary:
Note that CTxMemPool now requires a non-defaulted
CTxMemPool::Options for its constructor. Meaning that there's no need to
worry about a stray CTxMemPool constructor somewhere defaulting to
something incorrect. All instances of CTxMemPool construction are
addressed here in this commit.

We set options for CTxMemPool and construct it in many different ways. A
good example can be seen in how we determine CTxMemPool's check_ratio in
AppInitMain(...).

  1. We first set the default based on chainparams's DefaultConsistencyChecks()
  2. Then, we apply the ArgsManager option on top of that default
  3. Finally, we clamp the result of that between 0 and 1 Million

With this patch, most CTxMemPool construction are along the lines of:

MemPoolOptions mempool_opts{...default overrides...};
ApplyArgsManOptions(argsman, mempool_opts);
...hard overrides...
CTxMemPool pool{mempool_opts};

This "compositional" style of building options means that we can omit
unnecessary/irrelevant steps wherever we want but also maintain full
customizability.

For example:

  • For users of libbitcoinkernel, where we eventually want to remove ArgsManager, they simply won't call (or even know about) ApplyArgsManOptions.
  • See src/init.cpp to see how the check_ratio CTxMemPool option works after this change.

A MemPoolOptionsForTest helper was also added.

[META] As this patchset progresses, we will move more and more CTxMemPool-relevant options into MemPoolOptions and add their ArgsMan-related logic to ApplyArgsManOptions.

This is a partial backport of core#25290
https://github.com/bitcoin/bitcoin/pull/25290/commits/f1941e8bfd2eecc478c7660434b1ebf6a64095a0

Depends on D15298

Test Plan: ninja all check-all bitcoin-bench

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D15299

Details

Provenance
Carl Dong <contact@carldong.me>Authored on Mar 18 2022, 17:51
PiRKCommitted on Jan 30 2024, 09:35
PiRKPushed on Jan 30 2024, 09:35
Reviewer
Restricted Project
Differential Revision
D15299: pool: Add and use MemPoolOptions, ApplyArgsManOptions
Parents
rABC48fc05c41143: scripted-diff: Rename DEFAULT_MAX_MEMPOOL_SIZE to indicate SI unit
Branches
Unknown
Tags
Unknown