| 784 | }; |
| 785 | |
| 786 | bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws) |
| 787 | { |
| 788 | AssertLockHeld(cs_main); |
| 789 | AssertLockHeld(m_pool.cs); |
| 790 | const CTransactionRef& ptx = ws.m_ptx; |
| 791 | const CTransaction& tx = *ws.m_ptx; |
| 792 | const Txid& hash = ws.m_hash; |
| 793 | |
| 794 | // Copy/alias what we need out of args |
| 795 | const int64_t nAcceptTime = args.m_accept_time; |
| 796 | const bool bypass_limits = args.m_bypass_limits; |
| 797 | std::vector<COutPoint>& coins_to_uncache = args.m_coins_to_uncache; |
| 798 | |
| 799 | // Alias what we need out of ws |
| 800 | TxValidationState& state = ws.m_state; |
| 801 | |
| 802 | if (!CheckTransaction(tx, state)) { |
| 803 | return false; // state filled in by CheckTransaction |
| 804 | } |
| 805 | |
| 806 | // Coinbase is only valid in a block, not as a loose transaction |
| 807 | if (tx.IsCoinBase()) |
| 808 | return state.Invalid(TxValidationResult::TX_CONSENSUS, "coinbase"); |
| 809 | |
| 810 | // Rather not work on nonstandard transactions (unless -testnet/-regtest) |
| 811 | std::string reason; |
| 812 | if (m_pool.m_opts.require_standard && !IsStandardTx(tx, m_pool.m_opts.max_datacarrier_bytes, m_pool.m_opts.permit_bare_multisig, m_pool.m_opts.dust_relay_feerate, reason)) { |
| 813 | return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason); |
| 814 | } |
| 815 | |
| 816 | // Transactions smaller than 65 non-witness bytes are not relayed to mitigate CVE-2017-12842. |
| 817 | if (::GetSerializeSize(TX_NO_WITNESS(tx)) < MIN_STANDARD_TX_NONWITNESS_SIZE) |
| 818 | return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "tx-size-small"); |
| 819 | |
| 820 | // Only accept nLockTime-using transactions that can be mined in the next |
| 821 | // block; we don't want our mempool filled up with transactions that can't |
| 822 | // be mined yet. |
| 823 | if (!CheckFinalTxAtTip(*Assert(m_active_chainstate.m_chain.Tip()), tx)) { |
| 824 | return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final"); |
| 825 | } |
| 826 | |
| 827 | if (m_pool.exists(tx.GetWitnessHash())) { |
| 828 | // Exact transaction already exists in the mempool. |
| 829 | return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-already-in-mempool"); |
| 830 | } else if (m_pool.exists(tx.GetHash())) { |
| 831 | // Transaction with the same non-witness data but different witness (same txid, different |
| 832 | // wtxid) already exists in the mempool. |
| 833 | return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-same-nonwitness-data-in-mempool"); |
| 834 | } |
| 835 | |
| 836 | // Check for conflicts with in-memory transactions |
| 837 | for (const CTxIn &txin : tx.vin) |
| 838 | { |
| 839 | const CTransaction* ptxConflicting = m_pool.GetConflictTx(txin.prevout); |
| 840 | if (ptxConflicting) { |
| 841 | if (!args.m_allow_replacement) { |
| 842 | // Transaction conflicts with a mempool tx, but we're not allowing replacements in this context. |
| 843 | return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "bip125-replacement-disallowed"); |
nothing calls this directly
no test coverage detected