@@ -1083,65 +1083,15 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
1083
1083
{
1084
1084
AssertLockHeld (cs_main);
1085
1085
1086
+ // These context-free package limits can be done before taking the mempool lock.
1086
1087
PackageValidationState package_state;
1087
- const unsigned int package_count = txns. size ( );
1088
+ if (! CheckPackage (txns, package_state)) return PackageMempoolAcceptResult (package_state, {} );
1088
1089
1089
- // These context-free package limits can be checked before taking the mempool lock.
1090
- if (package_count > MAX_PACKAGE_COUNT) {
1091
- package_state.Invalid (PackageValidationResult::PCKG_POLICY, " package-too-many-transactions" );
1092
- return PackageMempoolAcceptResult (package_state, {});
1093
- }
1094
-
1095
- const int64_t total_size = std::accumulate (txns.cbegin (), txns.cend (), 0 ,
1096
- [](int64_t sum, const auto & tx) { return sum + GetVirtualTransactionSize (*tx); });
1097
- // If the package only contains 1 tx, it's better to report the policy violation on individual tx size.
1098
- if (package_count > 1 && total_size > MAX_PACKAGE_SIZE * 1000 ) {
1099
- package_state.Invalid (PackageValidationResult::PCKG_POLICY, " package-too-large" );
1100
- return PackageMempoolAcceptResult (package_state, {});
1101
- }
1102
-
1103
- // Construct workspaces and check package policies.
1104
1090
std::vector<Workspace> workspaces{};
1105
- workspaces.reserve (package_count);
1106
- {
1107
- std::unordered_set<uint256, SaltedTxidHasher> later_txids;
1108
- std::transform (txns.cbegin (), txns.cend (), std::inserter (later_txids, later_txids.end ()),
1109
- [](const auto & tx) { return tx->GetHash (); });
1110
- // Require the package to be sorted in order of dependency, i.e. parents appear before children.
1111
- // An unsorted package will fail anyway on missing-inputs, but it's better to quit earlier and
1112
- // fail on something less ambiguous (missing-inputs could also be an orphan or trying to
1113
- // spend nonexistent coins).
1114
- for (const auto & tx : txns) {
1115
- for (const auto & input : tx->vin ) {
1116
- if (later_txids.find (input.prevout .hash ) != later_txids.end ()) {
1117
- // The parent is a subsequent transaction in the package.
1118
- package_state.Invalid (PackageValidationResult::PCKG_POLICY, " package-not-sorted" );
1119
- return PackageMempoolAcceptResult (package_state, {});
1120
- }
1121
- }
1122
- later_txids.erase (tx->GetHash ());
1123
- workspaces.emplace_back (Workspace (tx));
1124
- }
1125
- }
1091
+ workspaces.reserve (txns.size ());
1092
+ std::transform (txns.cbegin (), txns.cend (), std::back_inserter (workspaces),
1093
+ [](const auto & tx) { return Workspace (tx); });
1126
1094
std::map<const uint256, const MempoolAcceptResult> results;
1127
- {
1128
- // Don't allow any conflicting transactions, i.e. spending the same inputs, in a package.
1129
- std::unordered_set<COutPoint, SaltedOutpointHasher> inputs_seen;
1130
- for (const auto & tx : txns) {
1131
- for (const auto & input : tx->vin ) {
1132
- if (inputs_seen.find (input.prevout ) != inputs_seen.end ()) {
1133
- // This input is also present in another tx in the package.
1134
- package_state.Invalid (PackageValidationResult::PCKG_POLICY, " conflict-in-package" );
1135
- return PackageMempoolAcceptResult (package_state, {});
1136
- }
1137
- }
1138
- // Batch-add all the inputs for a tx at a time. If we added them 1 at a time, we could
1139
- // catch duplicate inputs within a single tx. This is a more severe, consensus error,
1140
- // and we want to report that from CheckTransaction instead.
1141
- std::transform (tx->vin .cbegin (), tx->vin .cend (), std::inserter (inputs_seen, inputs_seen.end ()),
1142
- [](const auto & input) { return input.prevout ; });
1143
- }
1144
- }
1145
1095
1146
1096
LOCK (m_pool.cs );
1147
1097
0 commit comments