Skip to content

Commit 9bebf35

Browse files
committed
[validation] don't package validate if not policy or missing inputs
Package validation policy only differs from individual policy in its evaluation of feerate. Minimize DoS surface; don't validate all over again if we know the result will be the same.
1 parent 51edcff commit 9bebf35

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/validation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13421342
// the new transactions. This ensures we don't double-count transaction counts and sizes when
13431343
// checking ancestor/descendant limits, or double-count transaction fees for fee-related policy.
13441344
ATMPArgs single_args = ATMPArgs::SingleInPackageAccept(args);
1345+
bool quit_early{false};
13451346
std::vector<CTransactionRef> txns_new;
13461347
for (const auto& tx : package) {
13471348
const auto& wtxid = tx->GetWitnessHash();
@@ -1375,14 +1376,26 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13751376
// in package validation, because its fees should only be "used" once.
13761377
assert(m_pool.exists(GenTxid::Wtxid(wtxid)));
13771378
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;
13781391
} else {
13791392
txns_new.push_back(tx);
13801393
}
13811394
}
13821395
}
13831396

13841397
// Nothing to do if the entire package has already been submitted.
1385-
if (txns_new.empty()) {
1398+
if (quit_early || txns_new.empty()) {
13861399
// No package feerate when no package validation was done.
13871400
return PackageMempoolAcceptResult(package_state, std::move(results));
13881401
}

0 commit comments

Comments
 (0)