Skip to content

Commit bc013fe

Browse files
luke-jrinstagibbs
authored andcommitted
Bugfix: Pass correct virtual size to CheckPackageLimits
1 parent 533660c commit bc013fe

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/txmempool.cpp

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

199199
bool CTxMemPool::CheckPackageLimits(const Package& package,
200+
const int64_t total_vsize,
200201
std::string &errString) const
201202
{
202203
CTxMemPoolEntry::Parents staged_ancestors;
203-
int64_t total_size = 0;
204204
for (const auto& tx : package) {
205-
total_size += GetVirtualTransactionSize(*tx);
206205
for (const auto& input : tx->vin) {
207206
std::optional<txiter> piter = GetIter(input.prevout.hash);
208207
if (piter) {
@@ -217,7 +216,7 @@ bool CTxMemPool::CheckPackageLimits(const Package& package,
217216
// When multiple transactions are passed in, the ancestors and descendants of all transactions
218217
// considered together must be within limits even if they are not interdependent. This may be
219218
// stricter than the limits for each individual transaction.
220-
const auto ancestors{CalculateAncestorsAndCheckLimits(total_size, package.size(),
219+
const auto ancestors{CalculateAncestorsAndCheckLimits(total_vsize, package.size(),
221220
staged_ancestors, m_limits)};
222221
// It's possible to overestimate the ancestor/descendant totals.
223222
if (!ancestors.has_value()) errString = "possibly " + util::ErrorString(ancestors).original;

src/txmempool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,11 @@ 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] total_vsize Sum of virtual sizes for all transactions in package.
609610
* @param[out] errString Populated with error reason if a limit is hit.
610611
*/
611612
bool CheckPackageLimits(const Package& package,
613+
int64_t total_vsize,
612614
std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs);
613615

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

src/validation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ class MemPoolAccept
634634
// Enforce package mempool ancestor/descendant limits (distinct from individual
635635
// ancestor/descendant limits done in PreChecks).
636636
bool PackageMempoolChecks(const std::vector<CTransactionRef>& txns,
637+
int64_t total_vsize,
637638
PackageValidationState& package_state) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
638639

639640
// Run the script checks using our policy flags. As this can be slow, we should
@@ -1003,6 +1004,7 @@ bool MemPoolAccept::ReplacementChecks(Workspace& ws)
10031004
}
10041005

10051006
bool MemPoolAccept::PackageMempoolChecks(const std::vector<CTransactionRef>& txns,
1007+
const int64_t total_vsize,
10061008
PackageValidationState& package_state)
10071009
{
10081010
AssertLockHeld(cs_main);
@@ -1013,7 +1015,7 @@ bool MemPoolAccept::PackageMempoolChecks(const std::vector<CTransactionRef>& txn
10131015
{ return !m_pool.exists(GenTxid::Txid(tx->GetHash()));}));
10141016

10151017
std::string err_string;
1016-
if (!m_pool.CheckPackageLimits(txns, err_string)) {
1018+
if (!m_pool.CheckPackageLimits(txns, total_vsize, err_string)) {
10171019
// This is a package-wide error, separate from an individual transaction error.
10181020
return package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-mempool-limits", err_string);
10191021
}
@@ -1298,7 +1300,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
12981300
// because it's unnecessary. Also, CPFP carve out can increase the limit for individual
12991301
// transactions, but this exemption is not extended to packages in CheckPackageLimits().
13001302
std::string err_string;
1301-
if (txns.size() > 1 && !PackageMempoolChecks(txns, package_state)) {
1303+
if (txns.size() > 1 && !PackageMempoolChecks(txns, m_total_vsize, package_state)) {
13021304
return PackageMempoolAcceptResult(package_state, std::move(results));
13031305
}
13041306

0 commit comments

Comments
 (0)