| 50 | } |
| 51 | |
| 52 | bool IsConsistentPackage(const Package& txns) |
| 53 | { |
| 54 | // Don't allow any conflicting transactions, i.e. spending the same inputs, in a package. |
| 55 | std::unordered_set<COutPoint, SaltedOutpointHasher> inputs_seen; |
| 56 | for (const auto& tx : txns) { |
| 57 | if (tx->vin.empty()) { |
| 58 | // This function checks consistency based on inputs, and we can't do that if there are |
| 59 | // no inputs. Duplicate empty transactions are also not consistent with one another. |
| 60 | // This doesn't create false negatives, as unconfirmed transactions are not allowed to |
| 61 | // have no inputs. |
| 62 | return false; |
| 63 | } |
| 64 | for (const auto& input : tx->vin) { |
| 65 | if (inputs_seen.contains(input.prevout)) { |
| 66 | // This input is also present in another tx in the package. |
| 67 | return false; |
| 68 | } |
| 69 | } |
| 70 | // Batch-add all the inputs for a tx at a time. If we added them 1 at a time, we could |
| 71 | // catch duplicate inputs within a single tx. This is a more severe, consensus error, |
| 72 | // and we want to report that from CheckTransaction instead. |
| 73 | std::transform(tx->vin.cbegin(), tx->vin.cend(), std::inserter(inputs_seen, inputs_seen.end()), |
| 74 | [](const auto& input) { return input.prevout; }); |
| 75 | } |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | bool IsWellFormedPackage(const Package& txns, PackageValidationState& state) |
| 80 | { |