7#include <chainparams.h>
26 .signals =
node.validation_signals.get(),
58 return strprintf(
"txns size %u does not match tx results size %u", txns.size(), result.
m_tx_results.size());
60 for (
const auto& tx : txns) {
61 const auto& wtxid = tx->GetWitnessHash();
63 return strprintf(
"result not found for tx %s", wtxid.ToString());
68 if (expect_valid && atmp_result.m_state.IsInvalid()) {
69 return strprintf(
"tx %s unexpectedly failed: %s", wtxid.ToString(), atmp_result.m_state.ToString());
74 return strprintf(
"tx %s result replaced too many transactions",
79 if (!atmp_result.m_replaced_transactions.empty() &&
80 atmp_result.m_wtxids_fee_calculations.has_value() && atmp_result.m_wtxids_fee_calculations.value().size() > 2) {
81 return strprintf(
"tx %s was part of a too-large package RBF subpackage",
85 if (!atmp_result.m_replaced_transactions.empty() && mempool) {
88 if (atmp_result.m_wtxids_fee_calculations.has_value() && atmp_result.m_wtxids_fee_calculations.value().size() == 2) {
90 if (cluster.size() != 2)
return strprintf(
"tx %s has too many ancestors or descendants for a package rbf", wtxid.ToString());
96 if (atmp_result.m_base_fees.has_value() != (valid || mempool_entry)) {
97 return strprintf(
"tx %s result should %shave m_base_fees", wtxid.ToString(), valid || mempool_entry ?
"" :
"not ");
99 if (atmp_result.m_vsize.has_value() != (valid || mempool_entry)) {
100 return strprintf(
"tx %s result should %shave m_vsize", wtxid.ToString(), valid || mempool_entry ?
"" :
"not ");
105 if (atmp_result.m_other_wtxid.has_value() != diff_witness) {
106 return strprintf(
"tx %s result should %shave m_other_wtxid", wtxid.ToString(), diff_witness ?
"" :
"not ");
113 if (atmp_result.m_effective_feerate.has_value() != valid_or_reconsiderable) {
114 return strprintf(
"tx %s result should %shave m_effective_feerate",
115 wtxid.ToString(), valid ?
"" :
"not ");
117 if (atmp_result.m_wtxids_fee_calculations.has_value() != valid_or_reconsiderable) {
118 return strprintf(
"tx %s result should %shave m_effective_feerate",
119 wtxid.ToString(), valid ?
"" :
"not ");
126 return strprintf(
"tx %s should %sbe in mempool", wtxid.ToString(), txid_in_mempool ?
"" :
"not ");
131 return strprintf(
"wtxid %s should not be in mempool", wtxid.ToString());
134 for (
const auto& tx_ref : atmp_result.m_replaced_transactions) {
136 return strprintf(
"tx %s should not be in mempool as it was replaced", tx_ref->GetWitnessHash().ToString());
147 for (
const auto& tx_info : tx_pool.
infoAll()) {
148 const auto& entry = *
Assert(tx_pool.
GetEntry(tx_info.tx->GetHash()));
152 Assert(dust_indexes.size() < 2);
154 if (dust_indexes.empty())
continue;
157 Assert(entry.GetFee() == 0 && entry.GetModifiedFee() == 0);
160 const auto& children = entry.GetMemPoolChildrenConst();
164 Assert(children.size() < 2);
166 if (children.empty()) {
173 const auto& only_child = children.begin()->get().GetTx();
174 COutPoint dust_outpoint{tx_info.tx->GetHash(), dust_indexes[0]};
175 Assert(std::any_of(only_child.vin.begin(), only_child.vin.end(), [&dust_outpoint](
const CTxIn& txin) {
176 return txin.prevout == dust_outpoint;
184 for (
const auto& tx_info : tx_pool.
infoAll()) {
185 const auto& entry = *
Assert(tx_pool.
GetEntry(tx_info.tx->GetHash()));
197 if (entry.GetCountWithAncestors() > 1) {
200 const auto& parents = entry.GetMemPoolParentsConst();
203 }
else if (entry.GetCountWithAncestors() > 1) {
205 for (
const auto& parent : entry.GetMemPoolParentsConst()) {
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
An outpoint - a combination of a transaction hash and an index n into its vout.
An input of a transaction.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
const LockPoints & GetLockPoints() const
uint64_t GetSequence() const
unsigned int GetHeight() const
std::chrono::seconds GetTime() const
bool GetSpendsCoinbase() const
int64_t GetSigOpCost() const
CTransactionRef GetSharedTx() const
const CAmount & GetFee() const
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::unique_ptr< ChangeSet > GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs)
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
std::vector< TxMempoolInfo > infoAll() const
std::vector< txiter > GatherClusters(const std::vector< uint256 > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Collect the entire cluster of connected transactions for each transaction in txids.
bool exists(const GenTxid >xid) const
const CTxMemPoolEntry * GetEntry(const Txid &txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs)
static GenTxid Wtxid(const uint256 &hash)
static GenTxid Txid(const uint256 &hash)
std::string ToString() const
@ TX_RECONSIDERABLE
fails some policy, but might be acceptable if submitted in a (different) package
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
util::Result< void > ApplyArgsManOptions(const ArgsManager &args, BlockManager::Options &opts)
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
static constexpr uint32_t MAX_REPLACEMENT_CANDIDATES
Maximum number of transactions that can be replaced by RBF (Rule #5).
std::vector< uint32_t > GetDust(const CTransaction &tx, CFeeRate dust_relay_rate)
Get the vout index numbers of all dust outputs.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
A mutable version of CTransaction.
@ DIFFERENT_WITNESS
Valid, transaction was already in the mempool.
@ INVALID
Fully validated, valid.
Validation result for package mempool acceptance.
PackageValidationState m_state
std::map< uint256, MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const
Options struct containing options for constructing a CTxMemPool.
CFeeRate dust_relay_feerate
NodeContext struct containing references to chain state and connection state.
void AddToMempool(CTxMemPool &tx_pool, const CTxMemPoolEntry &entry)
One-line wrapper for creating a mempool changeset with a single transaction and applying it.
void CheckMempoolTRUCInvariants(const CTxMemPool &tx_pool)
For every transaction in tx_pool, check TRUC invariants:
CTxMemPool::Options MemPoolOptionsForTest(const NodeContext &node)
std::optional< std::string > CheckPackageMempoolAcceptResult(const Package &txns, const PackageMempoolAcceptResult &result, bool expect_valid, const CTxMemPool *mempool)
Check expected properties for every PackageMempoolAcceptResult, regardless of value.
void CheckMempoolEphemeralInvariants(const CTxMemPool &tx_pool)
Check that we never get into a state where an ephemeral dust transaction would be mined without the s...
static constexpr unsigned int TRUC_DESCENDANT_LIMIT
Maximum number of transactions including an unconfirmed tx and its descendants.
static constexpr int64_t TRUC_CHILD_MAX_VSIZE
Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed TRUC transaction.
static constexpr decltype(CTransaction::version) TRUC_VERSION
static constexpr int64_t TRUC_MAX_VSIZE
Maximum sigop-adjusted virtual size of all v3 transactions.
static constexpr unsigned int TRUC_ANCESTOR_LIMIT
Maximum number of transactions including a TRUC tx and all its mempool ancestors.