mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
Merge bitcoin/bitcoin#25290: [kernel 3a/n] Decouple CTxMemPool from ArgsManager
d1684beabefees: Pass in a filepath instead of referencing gArgs (Carl Dong)9a3d825c30init: Remove redundant -*mempool*, -limit* queries (Carl Dong)6c5c60c412mempool: Use m_limit for UpdateTransactionsFromBlock (Carl Dong)9e93b10301node/ifaces: Use existing MemPoolLimits (Carl Dong)38af2bcf35mempoolaccept: Use limits from mempool in constructor (Carl Dong)9333427014mempool: Introduce (still-unused) MemPoolLimits (Carl Dong)716bb5fbd3scripted-diff: Rename anc/desc size limit vars to indicate SI unit (Carl Dong)1ecc77321dscripted-diff: Rename DEFAULT_MEMPOOL_EXPIRY to indicate time unit (Carl Dong)aa9141cd81mempool: Pass in -mempoolexpiry instead of referencing gArgs (Carl Dong)51c7a41a5einit: Only determine maxmempool once (Carl Dong)386c9472c8mempool: Make GetMinFee() with custom size protected (Carl Dong)82f00de7a6mempool: Pass in -maxmempool instead of referencing gArgs (Carl Dong)f1941e8bfdpool: Add and use MemPoolOptions, ApplyArgsManOptions (Carl Dong)0199bd35bbfuzz/rbf: Add missing TestingSetup (Carl Dong)ccbaf546a6scripted-diff: Rename DEFAULT_MAX_MEMPOOL_SIZE to indicate SI unit (Carl Dong)fc02f77ca6ArgsMan: Add Get*Arg functions returning optional (Carl Dong) Pull request description: This is part of the `libbitcoinkernel` project: #24303, https://github.com/bitcoin/bitcoin/projects/18 ----- As mentioned in the Stage 1 Step 2 description of [the `libbitcoinkernel` project](https://github.com/bitcoin/bitcoin/issues/24303), `ArgsManager` will not be part of `libbitcoinkernel`. Therefore, it is important that we remove any dependence on `ArgsManager` by code that will be part of `libbitcoinkernel`. This is the first in a series of PRs aiming to achieve this. This PR removes `CTxMemPool+MempoolAccept`'s dependency on `ArgsManager` by introducing a `CTxMemPool::Options` struct, which is used to specify `CTxMemPool`'s various options at construction time. These options are: - `-maxmempool` -> `CTxMemPool::Options::max_size` - `-mempoolexpiry` -> `CTxMemPool::Options::expiry` - `-limitancestorcount` -> `CTxMemPool::Options::limits::ancestor_count` - `-limitancestorsize` -> `CTxMemPool::Options::limits::ancestor_size` - `-limitdescendantcount` -> `CTxMemPool::Options::limits::descendant_count` - `-limitdescendantsize` -> `CTxMemPool::Options::limits::descendant_size` More context can be gleaned from the commit messages. The important commits are: - 56eb479ded8bfb2ef635bb6f3b484f9d5952c70d "pool: Add and use MemPoolOptions, ApplyArgsManOptions" - a1e08b70f3068f4e8def1c630d8f50cd54da7832 "mempool: Pass in -maxmempool instead of referencing gArgs" - 6f4bf3ede5812b374828f08fc728ceded2f10024 "mempool: Pass in -mempoolexpiry instead of referencing gArgs" - 5958a7fe4806599fc620ee8c1a881ca10fa2dd16 "mempool: Introduce (still-unused) MemPoolLimits" Reviewers: Help needed in the following commits (see commit messages): - a1e08b70f3068f4e8def1c630d8f50cd54da7832 "mempool: Pass in -maxmempool instead of referencing gArgs" - 0695081a797e9a5d7787b78b0f8289dafcc6bff7 "node/ifaces: Use existing MemPoolLimits" Note to Reviewers: There are perhaps an infinite number of ways to architect `CTxMemPool::Options`, the current one tries to keep it simple, usable, and flexible. I hope we don't spend too much time arguing over the design here since that's not the point. In the case that you're 100% certain that a different design is strictly better than this one in every regard, please show us a fully-implemented branch. ----- TODO: - [x] Use the more ergonomic `CTxMemPool::Options` where appropriate - [x] Doxygen comments for `ApplyArgsManOptions`, `MemPoolOptions` ----- Questions for Reviewers: 1. Should we use `std::chrono::seconds` for `CTxMemPool::Options::expiry` and `CTxMemPool::m_expiry` instead of an `int64_t`? Something else? (`std::chrono::hours`?) 2. Should I merge `CTxMemPool::Limits` inside `CTxMemPool::Options`? ACKs for top commit: MarcoFalke: ACKd1684beabe🍜 ryanofsky: Code review ACKd1684beabe. Just minor cleanups since last review, mostly switching to brace initialization Tree-SHA512: 2c138e52d69f61c263f1c3648f01c801338a8f576762c815f478ef5148b8b2f51e91ded5c1be915e678c0b14f6cfba894b82afec58d999d39a7bb7c914736e0b
This commit is contained in:
@@ -609,36 +609,76 @@ bool ArgsManager::IsArgNegated(const std::string& strArg) const
|
||||
}
|
||||
|
||||
std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
|
||||
{
|
||||
return GetArg(strArg).value_or(strDefault);
|
||||
}
|
||||
|
||||
std::optional<std::string> ArgsManager::GetArg(const std::string& strArg) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToString(value, strDefault);
|
||||
return SettingToString(value);
|
||||
}
|
||||
|
||||
std::optional<std::string> SettingToString(const util::SettingsValue& value)
|
||||
{
|
||||
if (value.isNull()) return std::nullopt;
|
||||
if (value.isFalse()) return "0";
|
||||
if (value.isTrue()) return "1";
|
||||
if (value.isNum()) return value.getValStr();
|
||||
return value.get_str();
|
||||
}
|
||||
|
||||
std::string SettingToString(const util::SettingsValue& value, const std::string& strDefault)
|
||||
{
|
||||
return value.isNull() ? strDefault : value.isFalse() ? "0" : value.isTrue() ? "1" : value.isNum() ? value.getValStr() : value.get_str();
|
||||
return SettingToString(value).value_or(strDefault);
|
||||
}
|
||||
|
||||
int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) const
|
||||
{
|
||||
return GetIntArg(strArg).value_or(nDefault);
|
||||
}
|
||||
|
||||
std::optional<int64_t> ArgsManager::GetIntArg(const std::string& strArg) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToInt(value, nDefault);
|
||||
return SettingToInt(value);
|
||||
}
|
||||
|
||||
std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
|
||||
{
|
||||
if (value.isNull()) return std::nullopt;
|
||||
if (value.isFalse()) return 0;
|
||||
if (value.isTrue()) return 1;
|
||||
if (value.isNum()) return value.getInt<int64_t>();
|
||||
return LocaleIndependentAtoi<int64_t>(value.get_str());
|
||||
}
|
||||
|
||||
int64_t SettingToInt(const util::SettingsValue& value, int64_t nDefault)
|
||||
{
|
||||
return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.getInt<int64_t>() : LocaleIndependentAtoi<int64_t>(value.get_str());
|
||||
return SettingToInt(value).value_or(nDefault);
|
||||
}
|
||||
|
||||
bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
|
||||
{
|
||||
return GetBoolArg(strArg).value_or(fDefault);
|
||||
}
|
||||
|
||||
std::optional<bool> ArgsManager::GetBoolArg(const std::string& strArg) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToBool(value, fDefault);
|
||||
return SettingToBool(value);
|
||||
}
|
||||
|
||||
std::optional<bool> SettingToBool(const util::SettingsValue& value)
|
||||
{
|
||||
if (value.isNull()) return std::nullopt;
|
||||
if (value.isBool()) return value.get_bool();
|
||||
return InterpretBool(value.get_str());
|
||||
}
|
||||
|
||||
bool SettingToBool(const util::SettingsValue& value, bool fDefault)
|
||||
{
|
||||
return value.isNull() ? fDefault : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
|
||||
return SettingToBool(value).value_or(fDefault);
|
||||
}
|
||||
|
||||
bool ArgsManager::SoftSetArg(const std::string& strArg, const std::string& strValue)
|
||||
|
||||
Reference in New Issue
Block a user