@@ -1342,6 +1342,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1342
1342
// the new transactions. This ensures we don't double-count transaction counts and sizes when
1343
1343
// checking ancestor/descendant limits, or double-count transaction fees for fee-related policy.
1344
1344
ATMPArgs single_args = ATMPArgs::SingleInPackageAccept (args);
1345
+ bool quit_early{false };
1345
1346
std::vector<CTransactionRef> txns_new;
1346
1347
for (const auto & tx : package) {
1347
1348
const auto & wtxid = tx->GetWitnessHash ();
@@ -1375,14 +1376,26 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1375
1376
// in package validation, because its fees should only be "used" once.
1376
1377
assert (m_pool.exists (GenTxid::Wtxid (wtxid)));
1377
1378
results.emplace (wtxid, single_res);
1379
+ } else if (single_res.m_state .GetResult () != TxValidationResult::TX_MEMPOOL_POLICY &&
1380
+ single_res.m_state .GetResult () != TxValidationResult::TX_MISSING_INPUTS) {
1381
+ // Package validation policy only differs from individual policy in its evaluation
1382
+ // of feerate. For example, if a transaction fails here due to violation of a
1383
+ // consensus rule, the result will not change when it is submitted as part of a
1384
+ // package. To minimize the amount of repeated work, unless the transaction fails
1385
+ // due to feerate or missing inputs (its parent is a previous transaction in the
1386
+ // package that failed due to feerate), don't run package validation. Note that this
1387
+ // decision might not make sense if different types of packages are allowed in the
1388
+ // future. Continue individually validating the rest of the transactions, because
1389
+ // some of them may still be valid.
1390
+ quit_early = true ;
1378
1391
} else {
1379
1392
txns_new.push_back (tx);
1380
1393
}
1381
1394
}
1382
1395
}
1383
1396
1384
1397
// Nothing to do if the entire package has already been submitted.
1385
- if (txns_new.empty ()) {
1398
+ if (quit_early || txns_new.empty ()) {
1386
1399
// No package feerate when no package validation was done.
1387
1400
return PackageMempoolAcceptResult (package_state, std::move (results));
1388
1401
}
0 commit comments