| 583 | } |
| 584 | |
| 585 | static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx, |
| 586 | bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced, |
| 587 | bool bypass_limits, const CAmount& nAbsurdFee, std::vector<COutPoint>& coins_to_uncache, bool test_accept) |
| 588 | { |
| 589 | const CTransaction& tx = *ptx; |
| 590 | const uint256 hash = tx.GetHash(); |
| 591 | AssertLockHeld(cs_main); |
| 592 | LOCK(pool.cs); // mempool "read lock" (held through GetMainSignals().TransactionAddedToMempool()) |
| 593 | if (pfMissingInputs) { |
| 594 | *pfMissingInputs = false; |
| 595 | } |
| 596 | |
| 597 | if (!CheckTransaction(tx, state)) |
| 598 | return false; // state filled in by CheckTransaction |
| 599 | |
| 600 | // Coinbase is only valid in a block, not as a loose transaction |
| 601 | if (tx.IsCoinBase()) |
| 602 | return state.DoS(100, false, REJECT_INVALID, "coinbase"); |
| 603 | |
| 604 | // Rather not work on nonstandard transactions (unless -testnet/-regtest) |
| 605 | std::string reason; |
| 606 | if (fRequireStandard && !IsStandardTx(tx, reason)) |
| 607 | return state.DoS(0, false, REJECT_NONSTANDARD, reason); |
| 608 | |
| 609 | // Do not work on transactions that are too small. |
| 610 | // A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes. |
| 611 | // Transactions smaller than this are not relayed to reduce unnecessary malloc overhead. |
| 612 | if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) < MIN_STANDARD_TX_NONWITNESS_SIZE) |
| 613 | return state.DoS(0, false, REJECT_NONSTANDARD, "tx-size-small"); |
| 614 | |
| 615 | // Only accept nLockTime-using transactions that can be mined in the next |
| 616 | // block; we don't want our mempool filled up with transactions that can't |
| 617 | // be mined yet. |
| 618 | if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) |
| 619 | return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); |
| 620 | |
| 621 | // is it already in the memory pool? |
| 622 | if (pool.exists(hash)) { |
| 623 | return state.Invalid(false, REJECT_DUPLICATE, "txn-already-in-mempool"); |
| 624 | } |
| 625 | |
| 626 | // Check for conflicts with in-memory transactions |
| 627 | std::set<uint256> setConflicts; |
| 628 | for (const CTxIn &txin : tx.vin) |
| 629 | { |
| 630 | auto itConflicting = pool.mapNextTx.find(txin.prevout); |
| 631 | if (itConflicting != pool.mapNextTx.end()) |
| 632 | { |
| 633 | const CTransaction *ptxConflicting = itConflicting->second; |
| 634 | if (!setConflicts.count(ptxConflicting->GetHash())) |
| 635 | { |
| 636 | // Allow opt-out of transaction replacement by setting |
| 637 | // nSequence > MAX_BIP125_RBF_SEQUENCE (SEQUENCE_FINAL-2) on all inputs. |
| 638 | // |
| 639 | // SEQUENCE_FINAL-1 is picked to still allow use of nLockTime by |
| 640 | // non-replaceable transactions. All inputs rather than just one |
| 641 | // is for the sake of multi-party protocols, where we don't |
| 642 | // want a single party to be able to disable replacement. |
no test coverage detected