|
42 | 42 | #include <uint256.h>
|
43 | 43 | #include <undo.h>
|
44 | 44 | #include <util/check.h> // For NDEBUG compile time check
|
| 45 | +#include <util/hasher.h> |
45 | 46 | #include <util/moneystr.h>
|
46 | 47 | #include <util/rbf.h>
|
47 | 48 | #include <util/strencodings.h>
|
@@ -1093,12 +1094,29 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
|
1093 | 1094 | return PackageMempoolAcceptResult(package_state, {});
|
1094 | 1095 | }
|
1095 | 1096 |
|
| 1097 | + // Construct workspaces and check package policies. |
1096 | 1098 | std::vector<Workspace> workspaces{};
|
1097 | 1099 | workspaces.reserve(package_count);
|
1098 |
| - std::transform(txns.cbegin(), txns.cend(), std::back_inserter(workspaces), [](const auto& tx) { |
1099 |
| - return Workspace(tx); |
1100 |
| - }); |
1101 |
| - |
| 1100 | + { |
| 1101 | + std::unordered_set<uint256, SaltedTxidHasher> later_txids; |
| 1102 | + std::transform(txns.cbegin(), txns.cend(), std::inserter(later_txids, later_txids.end()), |
| 1103 | + [](const auto& tx) { return tx->GetHash(); }); |
| 1104 | + // Require the package to be sorted in order of dependency, i.e. parents appear before children. |
| 1105 | + // An unsorted package will fail anyway on missing-inputs, but it's better to quit earlier and |
| 1106 | + // fail on something less ambiguous (missing-inputs could also be an orphan or trying to |
| 1107 | + // spend nonexistent coins). |
| 1108 | + for (const auto& tx : txns) { |
| 1109 | + for (const auto& input : tx->vin) { |
| 1110 | + if (later_txids.find(input.prevout.hash) != later_txids.end()) { |
| 1111 | + // The parent is a subsequent transaction in the package. |
| 1112 | + package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-not-sorted"); |
| 1113 | + return PackageMempoolAcceptResult(package_state, {}); |
| 1114 | + } |
| 1115 | + } |
| 1116 | + later_txids.erase(tx->GetHash()); |
| 1117 | + workspaces.emplace_back(Workspace(tx)); |
| 1118 | + } |
| 1119 | + } |
1102 | 1120 | std::map<const uint256, const MempoolAcceptResult> results;
|
1103 | 1121 | {
|
1104 | 1122 | // Don't allow any conflicting transactions, i.e. spending the same inputs, in a package.
|
|
0 commit comments