Skip to content

Commit 275579d

Browse files
committed
Remove MemPoolAccept::m_limits, only have local copies for carveouts
1 parent f1a9fd6 commit 275579d

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/txmempool.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ util::Result<CTxMemPool::setEntries> CTxMemPool::CalculateAncestorsAndCheckLimit
197197
}
198198

199199
bool CTxMemPool::CheckPackageLimits(const Package& package,
200-
const Limits& limits,
201200
std::string &errString) const
202201
{
203202
CTxMemPoolEntry::Parents staged_ancestors;
@@ -208,8 +207,8 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
208207
std::optional<txiter> piter = GetIter(input.prevout.hash);
209208
if (piter) {
210209
staged_ancestors.insert(**piter);
211-
if (staged_ancestors.size() + package.size() > static_cast<uint64_t>(limits.ancestor_count)) {
212-
errString = strprintf("too many unconfirmed parents [limit: %u]", limits.ancestor_count);
210+
if (staged_ancestors.size() + package.size() > static_cast<uint64_t>(m_limits.ancestor_count)) {
211+
errString = strprintf("too many unconfirmed parents [limit: %u]", m_limits.ancestor_count);
213212
return false;
214213
}
215214
}
@@ -219,7 +218,7 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
219218
// considered together must be within limits even if they are not interdependent. This may be
220219
// stricter than the limits for each individual transaction.
221220
const auto ancestors{CalculateAncestorsAndCheckLimits(total_size, package.size(),
222-
staged_ancestors, limits)};
221+
staged_ancestors, m_limits)};
223222
// It's possible to overestimate the ancestor/descendant totals.
224223
if (!ancestors.has_value()) errString = "possibly " + util::ErrorString(ancestors).original;
225224
return ancestors.has_value();

src/txmempool.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,9 @@ class CTxMemPool
606606
* @param[in] package Transaction package being evaluated for acceptance
607607
* to mempool. The transactions need not be direct
608608
* ancestors/descendants of each other.
609-
* @param[in] limits Maximum number and size of ancestors and descendants
610609
* @param[out] errString Populated with error reason if a limit is hit.
611610
*/
612611
bool CheckPackageLimits(const Package& package,
613-
const Limits& limits,
614612
std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs);
615613

616614
/** Populate setDescendants with all in-mempool descendants of hash.

src/validation.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,7 @@ class MemPoolAccept
432432
m_pool(mempool),
433433
m_view(&m_dummy),
434434
m_viewmempool(&active_chainstate.CoinsTip(), m_pool),
435-
m_active_chainstate(active_chainstate),
436-
m_limits{m_pool.m_limits}
435+
m_active_chainstate(active_chainstate)
437436
{
438437
}
439438

@@ -683,8 +682,6 @@ class MemPoolAccept
683682

684683
Chainstate& m_active_chainstate;
685684

686-
CTxMemPool::Limits m_limits;
687-
688685
/** Whether the transaction(s) would replace any mempool transactions. If so, RBF rules apply. */
689686
bool m_rbf{false};
690687
};
@@ -873,6 +870,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
873870
if (!bypass_limits && !args.m_package_feerates && !CheckFeeRate(ws.m_vsize, ws.m_modified_fees, state)) return false;
874871

875872
ws.m_iters_conflicting = m_pool.GetIterSet(ws.m_conflicts);
873+
874+
// Note that these modifications are only applicable to single transaction scenarios;
875+
// carve-outs and package RBF are disabled for multi-transaction evaluations.
876+
CTxMemPool::Limits maybe_rbf_limits = m_pool.m_limits;
877+
876878
// Calculate in-mempool ancestors, up to a limit.
877879
if (ws.m_conflicts.size() == 1) {
878880
// In general, when we receive an RBF transaction with mempool conflicts, we want to know whether we
@@ -905,11 +907,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
905907
assert(ws.m_iters_conflicting.size() == 1);
906908
CTxMemPool::txiter conflict = *ws.m_iters_conflicting.begin();
907909

908-
m_limits.descendant_count += 1;
909-
m_limits.descendant_size_vbytes += conflict->GetSizeWithDescendants();
910+
maybe_rbf_limits.descendant_count += 1;
911+
maybe_rbf_limits.descendant_size_vbytes += conflict->GetSizeWithDescendants();
910912
}
911913

912-
auto ancestors{m_pool.CalculateMemPoolAncestors(*entry, m_limits)};
914+
auto ancestors{m_pool.CalculateMemPoolAncestors(*entry, maybe_rbf_limits)};
913915
if (!ancestors) {
914916
// If CalculateMemPoolAncestors fails second time, we want the original error string.
915917
// Contracting/payment channels CPFP carve-out:
@@ -925,9 +927,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
925927
// this, see https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-November/016518.html
926928
CTxMemPool::Limits cpfp_carve_out_limits{
927929
.ancestor_count = 2,
928-
.ancestor_size_vbytes = m_limits.ancestor_size_vbytes,
929-
.descendant_count = m_limits.descendant_count + 1,
930-
.descendant_size_vbytes = m_limits.descendant_size_vbytes + EXTRA_DESCENDANT_TX_SIZE_LIMIT,
930+
.ancestor_size_vbytes = maybe_rbf_limits.ancestor_size_vbytes,
931+
.descendant_count = maybe_rbf_limits.descendant_count + 1,
932+
.descendant_size_vbytes = maybe_rbf_limits.descendant_size_vbytes + EXTRA_DESCENDANT_TX_SIZE_LIMIT,
931933
};
932934
const auto error_message{util::ErrorString(ancestors).original};
933935
if (ws.m_vsize > EXTRA_DESCENDANT_TX_SIZE_LIMIT) {
@@ -1010,7 +1012,7 @@ bool MemPoolAccept::PackageMempoolChecks(const std::vector<CTransactionRef>& txn
10101012
{ return !m_pool.exists(GenTxid::Txid(tx->GetHash()));}));
10111013

10121014
std::string err_string;
1013-
if (!m_pool.CheckPackageLimits(txns, m_limits, err_string)) {
1015+
if (!m_pool.CheckPackageLimits(txns, err_string)) {
10141016
// This is a package-wide error, separate from an individual transaction error.
10151017
return package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-mempool-limits", err_string);
10161018
}
@@ -1165,7 +1167,7 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
11651167
// Re-calculate mempool ancestors to call addUnchecked(). They may have changed since the
11661168
// last calculation done in PreChecks, since package ancestors have already been submitted.
11671169
{
1168-
auto ancestors{m_pool.CalculateMemPoolAncestors(*ws.m_entry, m_limits)};
1170+
auto ancestors{m_pool.CalculateMemPoolAncestors(*ws.m_entry, m_pool.m_limits)};
11691171
if(!ancestors) {
11701172
results.emplace(ws.m_ptx->GetWitnessHash(), MempoolAcceptResult::Failure(ws.m_state));
11711173
// Since PreChecks() and PackageMempoolChecks() both enforce limits, this should never fail.

0 commit comments

Comments
 (0)