diff options
Diffstat (limited to 'src/test/util/txmempool.cpp')
-rw-r--r-- | src/test/util/txmempool.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/test/util/txmempool.cpp b/src/test/util/txmempool.cpp index 379c3c9329..2657104e7d 100644 --- a/src/test/util/txmempool.cpp +++ b/src/test/util/txmempool.cpp @@ -7,6 +7,7 @@ #include <chainparams.h> #include <node/context.h> #include <node/mempool_args.h> +#include <policy/v3_policy.h> #include <txmempool.h> #include <util/check.h> #include <util/time.h> @@ -21,6 +22,7 @@ CTxMemPool::Options MemPoolOptionsForTest(const NodeContext& node) // Default to always checking mempool regardless of // chainparams.DefaultConsistencyChecks for tests .check_ratio = 1, + .signals = node.validation_signals.get(), }; const auto result{ApplyArgsManOptions(*node.args, ::Params(), mempool_opts)}; Assert(result); @@ -66,12 +68,6 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns, return strprintf("tx %s unexpectedly failed: %s", wtxid.ToString(), atmp_result.m_state.ToString()); } - //m_replaced_transactions should exist iff the result was VALID - if (atmp_result.m_replaced_transactions.has_value() != valid) { - return strprintf("tx %s result should %shave m_replaced_transactions", - wtxid.ToString(), valid ? "" : "not "); - } - // m_vsize and m_base_fees should exist iff the result was VALID or MEMPOOL_ENTRY const bool mempool_entry{atmp_result.m_result_type == MempoolAcceptResult::ResultType::MEMPOOL_ENTRY}; if (atmp_result.m_base_fees.has_value() != (valid || mempool_entry)) { @@ -116,3 +112,34 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns, } return std::nullopt; } + +void CheckMempoolV3Invariants(const CTxMemPool& tx_pool) +{ + LOCK(tx_pool.cs); + for (const auto& tx_info : tx_pool.infoAll()) { + const auto& entry = *Assert(tx_pool.GetEntry(tx_info.tx->GetHash())); + if (tx_info.tx->nVersion == 3) { + // Check that special maximum virtual size is respected + Assert(entry.GetTxSize() <= V3_MAX_VSIZE); + + // Check that special v3 ancestor/descendant limits and rules are always respected + Assert(entry.GetCountWithDescendants() <= V3_DESCENDANT_LIMIT); + Assert(entry.GetCountWithAncestors() <= V3_ANCESTOR_LIMIT); + Assert(entry.GetSizeWithDescendants() <= V3_MAX_VSIZE + V3_CHILD_MAX_VSIZE); + Assert(entry.GetSizeWithAncestors() <= V3_MAX_VSIZE + V3_CHILD_MAX_VSIZE); + + // If this transaction has at least 1 ancestor, it's a "child" and has restricted weight. + if (entry.GetCountWithAncestors() > 1) { + Assert(entry.GetTxSize() <= V3_CHILD_MAX_VSIZE); + // All v3 transactions must only have v3 unconfirmed parents. + const auto& parents = entry.GetMemPoolParentsConst(); + Assert(parents.begin()->get().GetSharedTx()->nVersion == 3); + } + } else if (entry.GetCountWithAncestors() > 1) { + // All non-v3 transactions must only have non-v3 unconfirmed parents. + for (const auto& parent : entry.GetMemPoolParentsConst()) { + Assert(parent.get().GetSharedTx()->nVersion != 3); + } + } + } +} |