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.contains(tx->GetHash())) {
34 in_package_parents.push_back(i);
37 return in_package_parents;
60 const std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>& mempool_parents)
73 return strprintf(
"version=3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
74 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(), vsize,
TRUC_MAX_VSIZE);
78 return strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
79 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString());
82 if (mempool_parents.size()) {
84 return strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
85 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString());
89 const bool has_parent{mempool_parents.size() + in_package_parents.size() > 0};
93 return strprintf(
"version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
94 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
99 const auto parent_info = [&] {
100 if (mempool_parents.size() > 0) {
101 const auto& mempool_parent = &mempool_parents[0].get();
102 return ParentInfo{mempool_parent->GetTx().GetHash(),
103 mempool_parent->GetTx().GetWitnessHash(),
104 mempool_parent->GetTx().version,
107 auto& parent_index = in_package_parents.front();
108 auto& package_parent = package.at(parent_index);
110 package_parent->GetWitnessHash(),
111 package_parent->version,
118 return strprintf(
"version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)",
119 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
120 parent_info.m_txid.ToString(), parent_info.m_wtxid.ToString());
123 for (
const auto& package_tx : package) {
125 if (&(*package_tx) == &(*ptx))
continue;
127 for (
auto& input : package_tx->vin) {
131 if (input.prevout.hash == parent_info.m_txid) {
132 return strprintf(
"tx %s (wtxid=%s) would exceed descendant count limit",
133 parent_info.m_txid.ToString(),
134 parent_info.m_wtxid.ToString());
138 if (input.prevout.hash == ptx->GetHash()) {
139 return strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
140 package_tx->GetHash().ToString(), package_tx->GetWitnessHash().ToString());
145 if (parent_info.m_has_mempool_descendant) {
146 return strprintf(
"tx %s (wtxid=%s) would exceed descendant count limit",
147 parent_info.m_txid.ToString(), parent_info.m_wtxid.ToString());
152 for (
auto it : mempool_parents) {
154 return strprintf(
"non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
155 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
156 it.get().GetSharedTx()->GetHash().ToString(), it.get().GetSharedTx()->GetWitnessHash().ToString());
159 for (
const auto& index: in_package_parents) {
161 return strprintf(
"non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
162 ptx->GetHash().ToString(),
163 ptx->GetWitnessHash().ToString(),
164 package.at(index)->GetHash().ToString(),
165 package.at(index)->GetWitnessHash().ToString());
173 const std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>& mempool_parents,
174 const std::set<Txid>& direct_conflicts,
179 for (
const auto& entry_ref : mempool_parents) {
180 const auto& entry = &entry_ref.get();
182 return std::make_pair(
strprintf(
"non-version=3 tx %s (wtxid=%s) cannot spend from version=3 tx %s (wtxid=%s)",
183 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
184 entry->GetSharedTx()->GetHash().ToString(), entry->GetSharedTx()->GetWitnessHash().ToString()),
187 return std::make_pair(
strprintf(
"version=3 tx %s (wtxid=%s) cannot spend from non-version=3 tx %s (wtxid=%s)",
188 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(),
189 entry->GetSharedTx()->GetHash().ToString(), entry->GetSharedTx()->GetWitnessHash().ToString()),
202 return std::make_pair(
strprintf(
"version=3 tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
203 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString(), vsize,
TRUC_MAX_VSIZE),
209 return std::make_pair(
strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
210 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString()),
215 if (mempool_parents.size() > 0) {
219 return std::make_pair(
strprintf(
"tx %s (wtxid=%s) would have too many ancestors",
220 ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString()),
225 return std::make_pair(
strprintf(
"version=3 child tx %s (wtxid=%s) is too big: %u > %u virtual bytes",
231 const auto& parent_entry = mempool_parents[0].get();
237 descendants.erase(parent_it);
241 const bool child_will_be_replaced = !descendants.empty() &&
242 std::any_of(descendants.cbegin(), descendants.cend(),
243 [&direct_conflicts](
const CTxMemPool::txiter& child){return direct_conflicts.contains(child->GetTx().GetHash());});
255 return std::make_pair(
strprintf(
"tx %u (wtxid=%s) would exceed descendant count limit",
256 parent_entry.GetSharedTx()->GetHash().ToString(),
257 parent_entry.GetSharedTx()->GetWitnessHash().ToString()),
258 consider_sibling_eviction ? (*descendants.begin())->GetSharedTx() :
nullptr);
#define Assume(val)
Assume is the identity function.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
int64_t GetDescendantCount(txiter it) const
std::set< txiter, CompareIteratorByHash > setEntries
int64_t GetAncestorCount(const CTxMemPoolEntry &e) const
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of given transaction.
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::pair< std::string, CTransactionRef > > SingleTRUCChecks(const CTxMemPool &pool, const CTransactionRef &ptx, const std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > &mempool_parents, const std::set< Txid > &direct_conflicts, int64_t vsize)
Must be called for every transaction, 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::string > PackageTRUCChecks(const CTxMemPool &pool, const CTransactionRef &ptx, int64_t vsize, const Package &package, const std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > &mempool_parents)
Must be called for every transaction that is submitted within a package, 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.