Skip to content

Commit

Permalink
Remove MemPoolAccept::m_limits, only have local copies for carveouts
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Sep 14, 2023
1 parent f1a9fd6 commit 275579d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
7 changes: 3 additions & 4 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ util::Result<CTxMemPool::setEntries> CTxMemPool::CalculateAncestorsAndCheckLimit
}

bool CTxMemPool::CheckPackageLimits(const Package& package,
const Limits& limits,
std::string &errString) const
{
CTxMemPoolEntry::Parents staged_ancestors;
Expand All @@ -208,8 +207,8 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
std::optional<txiter> piter = GetIter(input.prevout.hash);
if (piter) {
staged_ancestors.insert(**piter);
if (staged_ancestors.size() + package.size() > static_cast<uint64_t>(limits.ancestor_count)) {
errString = strprintf("too many unconfirmed parents [limit: %u]", limits.ancestor_count);
if (staged_ancestors.size() + package.size() > static_cast<uint64_t>(m_limits.ancestor_count)) {
errString = strprintf("too many unconfirmed parents [limit: %u]", m_limits.ancestor_count);
return false;
}
}
Expand All @@ -219,7 +218,7 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
// considered together must be within limits even if they are not interdependent. This may be
// stricter than the limits for each individual transaction.
const auto ancestors{CalculateAncestorsAndCheckLimits(total_size, package.size(),
staged_ancestors, limits)};
staged_ancestors, m_limits)};
// It's possible to overestimate the ancestor/descendant totals.
if (!ancestors.has_value()) errString = "possibly " + util::ErrorString(ancestors).original;
return ancestors.has_value();
Expand Down
2 changes: 0 additions & 2 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,9 @@ class CTxMemPool
* @param[in] package Transaction package being evaluated for acceptance
* to mempool. The transactions need not be direct
* ancestors/descendants of each other.
* @param[in] limits Maximum number and size of ancestors and descendants
* @param[out] errString Populated with error reason if a limit is hit.
*/
bool CheckPackageLimits(const Package& package,
const Limits& limits,
std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs);

/** Populate setDescendants with all in-mempool descendants of hash.
Expand Down
26 changes: 14 additions & 12 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ class MemPoolAccept
m_pool(mempool),
m_view(&m_dummy),
m_viewmempool(&active_chainstate.CoinsTip(), m_pool),
m_active_chainstate(active_chainstate),
m_limits{m_pool.m_limits}
m_active_chainstate(active_chainstate)
{
}

Expand Down Expand Up @@ -683,8 +682,6 @@ class MemPoolAccept

Chainstate& m_active_chainstate;

CTxMemPool::Limits m_limits;

/** Whether the transaction(s) would replace any mempool transactions. If so, RBF rules apply. */
bool m_rbf{false};
};
Expand Down Expand Up @@ -873,6 +870,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
if (!bypass_limits && !args.m_package_feerates && !CheckFeeRate(ws.m_vsize, ws.m_modified_fees, state)) return false;

ws.m_iters_conflicting = m_pool.GetIterSet(ws.m_conflicts);

// Note that these modifications are only applicable to single transaction scenarios;
// carve-outs and package RBF are disabled for multi-transaction evaluations.
CTxMemPool::Limits maybe_rbf_limits = m_pool.m_limits;

// Calculate in-mempool ancestors, up to a limit.
if (ws.m_conflicts.size() == 1) {
// In general, when we receive an RBF transaction with mempool conflicts, we want to know whether we
Expand Down Expand Up @@ -905,11 +907,11 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
assert(ws.m_iters_conflicting.size() == 1);
CTxMemPool::txiter conflict = *ws.m_iters_conflicting.begin();

m_limits.descendant_count += 1;
m_limits.descendant_size_vbytes += conflict->GetSizeWithDescendants();
maybe_rbf_limits.descendant_count += 1;
maybe_rbf_limits.descendant_size_vbytes += conflict->GetSizeWithDescendants();
}

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

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

0 comments on commit 275579d

Please sign in to comment.