21 std::vector<size_t> in_package_parents;
23 std::set<Txid> possible_parents;
24 for (
auto &input : ptx->vin) {
25 possible_parents.insert(input.prevout.hash);
28 for (
size_t i{0}; i < package.size(); ++i) {
29 const auto& tx = package.at(i);
32 if (&(*tx) == &(*ptx))
break;
33 if (possible_parents.count(tx->GetHash())) {
34 in_package_parents.push_back(i);
37 return in_package_parents;
72 return strprintf(
"version=3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
73 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(), vsize,
TRUC_MAX_VSIZE);
77 return strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
78 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString());
81 const bool has_parent{mempool_ancestors.size() + in_package_parents.size() > 0};
85 return strprintf(
"version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
86 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
91 const auto parent_info = [&] {
92 if (mempool_ancestors.size() > 0) {
93 auto& mempool_parent = *mempool_ancestors.begin();
94 return ParentInfo{mempool_parent->GetTx().GetHash(),
95 mempool_parent->GetTx().GetWitnessHash(),
96 mempool_parent->GetTx().version,
97 mempool_parent->GetCountWithDescendants() > 1};
99 auto& parent_index = in_package_parents.front();
100 auto& package_parent = package.at(parent_index);
102 package_parent->GetWitnessHash(),
103 package_parent->version,
110 return strprintf(
"version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)",
111 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
112 parent_info.m_txid.ToString(), parent_info.m_wtxid.ToString());
115 for (
const auto& package_tx : package) {
117 if (&(*package_tx) == &(*ptx))
continue;
119 for (
auto& input : package_tx->vin) {
123 if (input.prevout.hash == parent_info.m_txid) {
124 return strprintf(
"tx %s (wtxid=%s) would exceed descendant count limit",
125 parent_info.m_txid.ToString(),
126 parent_info.m_wtxid.ToString());
130 if (input.prevout.hash == ptx->GetHash()) {
131 return strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
132 package_tx->GetHash().ToString(), package_tx->GetWitnessHash().ToString());
137 if (parent_info.m_has_mempool_descendant) {
138 return strprintf(
"tx %s (wtxid=%s) would exceed descendant count limit",
139 parent_info.m_txid.ToString(), parent_info.m_wtxid.ToString());
144 for (
auto it : mempool_ancestors) {
146 return strprintf(
"non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
147 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
148 it->GetSharedTx()->GetHash().ToString(), it->GetSharedTx()->GetWitnessHash().ToString());
151 for (
const auto& index: in_package_parents) {
153 return strprintf(
"non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
154 ptx->GetHash().ToString(),
155 ptx->GetWitnessHash().ToString(),
156 package.at(index)->GetHash().ToString(),
157 package.at(index)->GetWitnessHash().ToString());
166 const std::set<Txid>& direct_conflicts,
170 for (
const auto& entry : mempool_ancestors) {
172 return std::make_pair(
strprintf(
"non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
173 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
174 entry->GetSharedTx()->GetHash().ToString(), entry->GetSharedTx()->GetWitnessHash().ToString()),
177 return std::make_pair(
strprintf(
"version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)",
178 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
179 entry->GetSharedTx()->GetHash().ToString(), entry->GetSharedTx()->GetWitnessHash().ToString()),
192 return std::make_pair(
strprintf(
"version=3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
193 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(), vsize,
TRUC_MAX_VSIZE),
199 return std::make_pair(
strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
200 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString()),
205 if (mempool_ancestors.size() > 0) {
208 return std::make_pair(
strprintf(
"version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
214 const auto& parent_entry = *mempool_ancestors.begin();
218 const auto& children = parent_entry->GetMemPoolChildrenConst();
222 const bool child_will_be_replaced = !children.empty() &&
223 std::any_of(children.cbegin(), children.cend(),
224 [&direct_conflicts](
const CTxMemPoolEntry& child){return direct_conflicts.count(child.GetTx().GetHash()) > 0;});
225 if (parent_entry->GetCountWithDescendants() + 1 >
TRUC_DESCENDANT_LIMIT && !child_will_be_replaced) {
231 const bool consider_sibling_eviction{parent_entry->GetCountWithDescendants() == 2 &&
232 children.begin()->get().GetCountWithAncestors() == 2};
236 return std::make_pair(
strprintf(
"tx %u (wtxid=%s) would exceed descendant count limit",
237 parent_entry->GetSharedTx()->GetHash().ToString(),
238 parent_entry->GetSharedTx()->GetWitnessHash().ToString()),
239 consider_sibling_eviction ? children.begin()->get().GetSharedTx() :
nullptr);
#define Assume(val)
Assume is the identity function.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
std::set< txiter, CompareIteratorByHash > setEntries
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
std::shared_ptr< const CTransaction > CTransactionRef
Helper for PackageTRUCChecks, storing info for a mempool or package parent.
decltype(CTransaction::version) m_version
version used to check inheritance of TRUC and non-TRUC
ParentInfo(const Txid &txid, const Wtxid &wtxid, decltype(CTransaction::version) version, bool has_mempool_descendant)
bool m_has_mempool_descendant
If parent is in mempool, whether it has any descendants in mempool.
const Txid & m_txid
Txid used to identify this parent by prevout.
const Wtxid & m_wtxid
Wtxid used for debug string.
std::optional< std::string > PackageTRUCChecks(const CTransactionRef &ptx, int64_t vsize, const Package &package, const CTxMemPool::setEntries &mempool_ancestors)
Must be called for every transaction that is submitted within a package, even if not TRUC.
std::vector< size_t > FindInPackageParents(const Package &package, const CTransactionRef &ptx)
Helper for PackageTRUCChecks: Returns a vector containing the indices of transactions (within package...
std::optional< std::pair< std::string, CTransactionRef > > SingleTRUCChecks(const CTransactionRef &ptx, const CTxMemPool::setEntries &mempool_ancestors, const std::set< Txid > &direct_conflicts, int64_t vsize)
Must be called for every transaction, even if not TRUC.
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.