| 984 | |
| 985 | |
| 986 | bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransaction& tx, bool fLimitFree, bool* pfMissingInputs, list<CTransactionRef>* plTxnReplaced, bool fRejectInsaneFee, bool ignoreFees) |
| 987 | { |
| 988 | const uint256 hash = tx.GetHash(); |
| 989 | AssertLockHeld(cs_main); |
| 990 | if (pfMissingInputs) { |
| 991 | *pfMissingInputs = false; |
| 992 | } |
| 993 | if (!CheckTransaction(tx, state)) |
| 994 | return error("%s: CheckTransaction: %s, %s", __func__, hash.ToString(), FormatStateMessage(state)); |
| 995 | |
| 996 | // Coinbase is only valid in a block, not as a loose transaction |
| 997 | if (tx.IsCoinBase()) |
| 998 | return state.DoS(100, error("AcceptToMemoryPool: : coinbase as individual tx"), REJECT_INVALID, "coinbase"); |
| 999 | |
| 1000 | //Coinstake is also only valid in a block, not as a loose transaction |
| 1001 | if (tx.IsCoinStake()) |
| 1002 | return state.DoS(100, error("AcceptToMemoryPool: coinstake as individual tx"), |
| 1003 | REJECT_INVALID, "coinstake"); |
| 1004 | |
| 1005 | const CChainParams& chainParams = Params(); |
| 1006 | // Reject transactions with witness before segregated witness activates (override with -prematurewitness) |
| 1007 | bool witnessEnabled = IsWitnessEnabled(chainActive.Tip(), chainParams.GetConsensus()); |
| 1008 | if (!GetBoolArg("-prematurewitness", false) && tx.HasWitness() && !witnessEnabled) { |
| 1009 | return state.DoS(0, false, REJECT_NONSTANDARD, "no-witness-yet", true); |
| 1010 | } |
| 1011 | |
| 1012 | // Rather not work on nonstandard transactions (unless -testnet/-regtest) |
| 1013 | string reason; |
| 1014 | if (fRequireStandard && !IsStandardTx(tx, reason, witnessEnabled)) |
| 1015 | return state.DoS(0, |
| 1016 | error("AcceptToMemoryPool : nonstandard transaction: %s", reason), |
| 1017 | REJECT_NONSTANDARD, reason); |
| 1018 | |
| 1019 | if (!IsFinalTx(tx, chainActive.Height() + 1)) |
| 1020 | return state.DoS(0, error("AcceptToMemoryPool: non-final"), REJECT_NONSTANDARD, "non-final"); |
| 1021 | |
| 1022 | // is it already in the memory pool? |
| 1023 | if (pool.exists(hash)) |
| 1024 | return false; |
| 1025 | |
| 1026 | // ----------- INSTANTX transaction scanning ----------- |
| 1027 | |
| 1028 | for (const CTxIn& in : tx.vin) { |
| 1029 | if (mapLockedInputs.count(in.prevout)) { |
| 1030 | if (mapLockedInputs[in.prevout] != tx.GetHash()) { |
| 1031 | return state.DoS(0, |
| 1032 | error("AcceptToMemoryPool : conflicts with existing transaction lock: %s", reason), |
| 1033 | REJECT_INVALID, "tx-lock-conflict"); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | // Mempool blocking code |
| 1038 | const char *mempoolbanname; |
| 1039 | BOOST_FOREACH(const CTxOut& txout, tx.vout) { |
| 1040 | mempoolbanname = txout.scriptPubKey.IsMempoolbanned(); |
| 1041 | if (mempoolbanname) { |
| 1042 | LogPrintf("AcceptToMemoryPool : not accepting transaction %s with mempoolbanned output (%s)\n", tx.GetHash().ToString().c_str(), mempoolbanname); |
| 1043 | return error("AcceptToMemoryPool : not accepting transaction %s with mempoolbanned output (%s)\n", tx.GetHash().ToString().c_str(), mempoolbanname); |
no test coverage detected