IsTopoSortedPackage where a set of txids has been pre-populated. The set is assumed to be correct and * is mutated within this function (even if return value is false). */
| 17 | /** IsTopoSortedPackage where a set of txids has been pre-populated. The set is assumed to be correct and |
| 18 | * is mutated within this function (even if return value is false). */ |
| 19 | bool IsTopoSortedPackage(const Package& txns, std::unordered_set<Txid, SaltedTxidHasher>& later_txids) |
| 20 | { |
| 21 | // Avoid misusing this function: later_txids should contain the txids of txns. |
| 22 | Assume(txns.size() == later_txids.size()); |
| 23 | |
| 24 | // later_txids always contains the txids of this transaction and the ones that come later in |
| 25 | // txns. If any transaction's input spends a tx in that set, we've found a parent placed later |
| 26 | // than its child. |
| 27 | for (const auto& tx : txns) { |
| 28 | for (const auto& input : tx->vin) { |
| 29 | if (later_txids.contains(input.prevout.hash)) { |
| 30 | // The parent is a subsequent transaction in the package. |
| 31 | return false; |
| 32 | } |
| 33 | } |
| 34 | // Avoid misusing this function: later_txids must contain every tx. |
| 35 | Assume(later_txids.erase(tx->GetHash()) == 1); |
| 36 | } |
| 37 | |
| 38 | // Avoid misusing this function: later_txids should have contained the txids of txns. |
| 39 | Assume(later_txids.empty()); |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | bool IsTopoSortedPackage(const Package& txns) |
| 44 | { |