| 1015 | } |
| 1016 | |
| 1017 | PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions( |
| 1018 | const std::vector<CTransactionRef> &txns, ATMPArgs &args) { |
| 1019 | AssertLockHeld(cs_main); |
| 1020 | |
| 1021 | // These context-free package limits can be done before taking the mempool |
| 1022 | // lock. |
| 1023 | PackageValidationState package_state; |
| 1024 | if (!CheckPackage(txns, package_state)) { |
| 1025 | return PackageMempoolAcceptResult(package_state, {}); |
| 1026 | } |
| 1027 | |
| 1028 | std::vector<Workspace> workspaces{}; |
| 1029 | workspaces.reserve(txns.size()); |
| 1030 | std::transform( |
| 1031 | txns.cbegin(), txns.cend(), std::back_inserter(workspaces), |
| 1032 | [this](const auto &tx) { |
| 1033 | return Workspace( |
| 1034 | tx, GetNextBlockScriptFlags(m_active_chainstate.m_chain.Tip(), |
| 1035 | m_active_chainstate.m_chainman)); |
| 1036 | }); |
| 1037 | std::map<TxId, MempoolAcceptResult> results; |
| 1038 | |
| 1039 | LOCK(m_pool.cs); |
| 1040 | |
| 1041 | // Do all PreChecks first and fail fast to avoid running expensive script |
| 1042 | // checks when unnecessary. |
| 1043 | std::vector<TxId> valid_txids; |
| 1044 | for (Workspace &ws : workspaces) { |
| 1045 | if (!PreChecks(args, ws)) { |
| 1046 | package_state.Invalid(PackageValidationResult::PCKG_TX, |
| 1047 | "transaction failed"); |
| 1048 | // Exit early to avoid doing pointless work. Update the failed tx |
| 1049 | // result; the rest are unfinished. |
| 1050 | results.emplace(ws.m_ptx->GetId(), |
| 1051 | MempoolAcceptResult::Failure(ws.m_state)); |
| 1052 | return PackageMempoolAcceptResult(package_state, |
| 1053 | std::move(results)); |
| 1054 | } |
| 1055 | // Make the coins created by this transaction available for subsequent |
| 1056 | // transactions in the package to spend. |
| 1057 | m_viewmempool.PackageAddTransaction(ws.m_ptx); |
| 1058 | valid_txids.push_back(ws.m_ptx->GetId()); |
| 1059 | } |
| 1060 | |
| 1061 | // Transactions must meet two minimum feerates: the mempool minimum fee and |
| 1062 | // min relay fee. For transactions consisting of exactly one child and its |
| 1063 | // parents, it suffices to use the package feerate |
| 1064 | // (total modified fees / total size or vsize) to check this requirement. |
| 1065 | // Note that this is an aggregate feerate; this function has not checked |
| 1066 | // that there are transactions too low feerate to pay for themselves, or |
| 1067 | // that the child transactions are higher feerate than their parents. Using |
| 1068 | // aggregate feerate may allow "parents pay for child" behavior and permit |
| 1069 | // a child that is below mempool minimum feerate. To avoid these behaviors, |
| 1070 | // callers of AcceptMultipleTransactions need to restrict txns topology |
| 1071 | // (e.g. to ancestor sets) and check the feerates of individuals and |
| 1072 | // subsets. |
| 1073 | const auto m_total_size = std::accumulate( |
| 1074 | workspaces.cbegin(), workspaces.cend(), int64_t{0}, |
no test coverage detected