MCPcopy Create free account
hub / github.com/ElementsProject/elements / PreChecks

Method PreChecks

src/validation.cpp:686–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

684};
685
686bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
687{
688 AssertLockHeld(cs_main);
689 AssertLockHeld(m_pool.cs);
690 const CTransactionRef& ptx = ws.m_ptx;
691 const CTransaction& tx = *ws.m_ptx;
692 const uint256& hash = ws.m_hash;
693
694 // Copy/alias what we need out of args
695 const int64_t nAcceptTime = args.m_accept_time;
696 const bool bypass_limits = args.m_bypass_limits;
697 std::vector<COutPoint>& coins_to_uncache = args.m_coins_to_uncache;
698 const CChainParams& chainparams = args.m_chainparams;
699
700 // Alias what we need out of ws
701 TxValidationState& state = ws.m_state;
702 std::unique_ptr<CTxMemPoolEntry>& entry = ws.m_entry;
703 std::set<std::pair<uint256, COutPoint>>& setPeginsSpent = ws.m_set_pegins_spent;
704
705 if (!CheckTransaction(tx, state)) {
706 return false; // state filled in by CheckTransaction
707 }
708
709 // Coinbase is only valid in a block, not as a loose transaction
710 if (tx.IsCoinBase())
711 return state.Invalid(TxValidationResult::TX_CONSENSUS, "coinbase");
712
713 // Rather not work on nonstandard transactions (unless -testnet/-regtest)
714 std::string reason;
715 if (fRequireStandard && !IsStandardTx(tx, reason))
716 return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason);
717
718 // And now do PAK checks. Filtered by next blocks' enforced list
719 if (chainparams.GetEnforcePak()) {
720 if (!IsPAKValidTx(tx, GetActivePAKList(m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus()), chainparams.ParentGenesisBlockHash(), chainparams.GetConsensus().pegged_asset)) {
721 return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "invalid-pegout-proof");
722 }
723 }
724
725 // Check unblinded issuance is in MoneyRange if configured
726 if (!chainparams.GetAcceptUnlimitedIssuances() && !IsIssuanceInMoneyRange(tx)) {
727 return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "issuance-out-of-range", "Issuance is greater than 21 million and acceptunlimitedissuances is not enabled.");
728 }
729
730 // Do not work on transactions that are too small.
731 // A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes.
732 // Transactions smaller than this are not relayed to mitigate CVE-2017-12842 by not relaying
733 // 64-byte transactions.
734 if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) < MIN_STANDARD_TX_NONWITNESS_SIZE)
735 return state.Invalid(TxValidationResult::TX_NOT_STANDARD, "tx-size-small");
736
737 // Only accept nLockTime-using transactions that can be mined in the next
738 // block; we don't want our mempool filled up with transactions that can't
739 // be mined yet.
740 if (!CheckFinalTx(m_active_chainstate.m_chain.Tip(), tx, STANDARD_LOCKTIME_VERIFY_FLAGS))
741 return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final");
742
743 if (m_pool.exists(GenTxid::Wtxid(tx.GetWitnessHash()))) {

Callers

nothing calls this directly

Calls 15

CheckTransactionFunction · 0.85
IsPAKValidTxFunction · 0.85
GetActivePAKListFunction · 0.85
IsIssuanceInMoneyRangeFunction · 0.85
GetSerializeSizeFunction · 0.85
CheckFinalTxFunction · 0.85
SignalsOptInRBFFunction · 0.85
GetValidFedpegScriptsFunction · 0.85
IsValidPeginWitnessFunction · 0.85
CheckSequenceLocksFunction · 0.85
AreInputsStandardFunction · 0.85
IsWitnessStandardFunction · 0.85

Tested by

no test coverage detected