Skip to content

Commit be2e4d9

Browse files
glozowinstagibbs
andcommitted
[validation] when quitting early in AcceptPackage, set package_state and tx result
Bug: not setting package_state means package_state.IsValid() == true and the caller does not know that this failed. We won't be validating this transaction again, so it makes sense to return this failure to the caller. Rename package_state to package_state_quit_early to make it more clear what this variable is used for and what its scope is. Co-authored-by: Greg Sanders <[email protected]>
1 parent 196a43e commit be2e4d9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/validation.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,19 +1273,20 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
12731273
PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package, ATMPArgs& args)
12741274
{
12751275
AssertLockHeld(cs_main);
1276-
PackageValidationState package_state;
1276+
// Used if returning a PackageMempoolAcceptResult directly from this function.
1277+
PackageValidationState package_state_quit_early;
12771278

12781279
// Check that the package is well-formed. If it isn't, we won't try to validate any of the
12791280
// transactions and thus won't return any MempoolAcceptResults, just a package-wide error.
12801281

12811282
// Context-free package checks.
1282-
if (!CheckPackage(package, package_state)) return PackageMempoolAcceptResult(package_state, {});
1283+
if (!CheckPackage(package, package_state_quit_early)) return PackageMempoolAcceptResult(package_state_quit_early, {});
12831284

12841285
// All transactions in the package must be a parent of the last transaction. This is just an
12851286
// opportunity for us to fail fast on a context-free check without taking the mempool lock.
12861287
if (!IsChildWithParents(package)) {
1287-
package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-not-child-with-parents");
1288-
return PackageMempoolAcceptResult(package_state, {});
1288+
package_state_quit_early.Invalid(PackageValidationResult::PCKG_POLICY, "package-not-child-with-parents");
1289+
return PackageMempoolAcceptResult(package_state_quit_early, {});
12891290
}
12901291

12911292
// IsChildWithParents() guarantees the package is > 1 transactions.
@@ -1317,8 +1318,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13171318
return unconfirmed_parent_txids.count(input.prevout.hash) > 0 || m_view.HaveCoin(input.prevout);
13181319
};
13191320
if (!std::all_of(child->vin.cbegin(), child->vin.cend(), package_or_confirmed)) {
1320-
package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-not-child-with-unconfirmed-parents");
1321-
return PackageMempoolAcceptResult(package_state, {});
1321+
package_state_quit_early.Invalid(PackageValidationResult::PCKG_POLICY, "package-not-child-with-unconfirmed-parents");
1322+
return PackageMempoolAcceptResult(package_state_quit_early, {});
13221323
}
13231324
// Protect against bugs where we pull more inputs from disk that miss being added to
13241325
// coins_to_uncache. The backend will be connected again when needed in PreChecks.
@@ -1381,6 +1382,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13811382
// future. Continue individually validating the rest of the transactions, because
13821383
// some of them may still be valid.
13831384
quit_early = true;
1385+
package_state_quit_early.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
1386+
results.emplace(wtxid, single_res);
13841387
} else {
13851388
txns_new.push_back(tx);
13861389
}
@@ -1390,7 +1393,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13901393
// Nothing to do if the entire package has already been submitted.
13911394
if (quit_early || txns_new.empty()) {
13921395
// No package feerate when no package validation was done.
1393-
return PackageMempoolAcceptResult(package_state, std::move(results));
1396+
return PackageMempoolAcceptResult(package_state_quit_early, std::move(results));
13941397
}
13951398
// Validate the (deduplicated) transactions as a package.
13961399
auto submission_result = AcceptMultipleTransactions(txns_new, args);

0 commit comments

Comments
 (0)