Bitcoin Core 28.99.0
P2P Digital Currency
Functions | Variables
truc_policy.h File Reference
#include <consensus/amount.h>
#include <policy/packages.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <txmempool.h>
#include <util/result.h>
#include <set>
#include <string>
Include dependency graph for truc_policy.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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. More...
 
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. More...
 

Variables

static constexpr decltype(CTransaction::versionTRUC_VERSION {3}
 
static constexpr unsigned int TRUC_DESCENDANT_LIMIT {2}
 Maximum number of transactions including an unconfirmed tx and its descendants. More...
 
static constexpr unsigned int TRUC_ANCESTOR_LIMIT {2}
 Maximum number of transactions including a TRUC tx and all its mempool ancestors. More...
 
static constexpr int64_t TRUC_MAX_VSIZE {10000}
 Maximum sigop-adjusted virtual size of all v3 transactions. More...
 
static constexpr int64_t TRUC_CHILD_MAX_VSIZE {1000}
 Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed TRUC transaction. More...
 

Function Documentation

◆ PackageTRUCChecks()

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.

For each transaction in a package: If it's not a TRUC transaction, verify it has no direct TRUC parents in the mempool or the package.

If it is a TRUC transaction, verify that any direct parents in the mempool or the package are TRUC. If such a parent exists, verify that parent has no other children in the package or the mempool, and that the transaction itself has no children in the package.

If any TRUC violations in the package exist, this test will fail for one of them:

  • if a TRUC transaction T has a parent in the mempool and a child in the package, then PTRUCC(T) will fail
  • if a TRUC transaction T has a parent in the package and a child in the package, then PTRUCC(T) will fail
  • if a TRUC transaction T and a TRUC (sibling) transaction U have some parent in the mempool, then PTRUCC(T) and PTRUCC(U) will fail
  • if a TRUC transaction T and a TRUC (sibling) transaction U have some parent in the package, then PTRUCC(T) and PTRUCC(U) will fail
  • if a TRUC transaction T has a parent P and a grandparent G in the package, then PTRUCC(P) will fail (though PTRUCC(G) and PTRUCC(T) might succeed).
Returns
debug string if an error occurs, std::nullopt otherwise.

Definition at line 58 of file truc_policy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SingleTRUCChecks()

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.

Not strictly necessary for transactions accepted through AcceptMultipleTransactions.

Checks the following rules:

  1. A TRUC tx must only have TRUC unconfirmed ancestors.
  2. A non-TRUC tx must only have non-TRUC unconfirmed ancestors.
  3. A TRUC's ancestor set, including itself, must be within TRUC_ANCESTOR_LIMIT.
  4. A TRUC's descendant set, including itself, must be within TRUC_DESCENDANT_LIMIT.
  5. If a TRUC tx has any unconfirmed ancestors, the tx's sigop-adjusted vsize must be within TRUC_CHILD_MAX_VSIZE.
  6. A TRUC tx must be within TRUC_MAX_VSIZE.
Parameters
[in]mempool_ancestorsThe in-mempool ancestors of ptx.
[in]direct_conflictsIn-mempool transactions this tx conflicts with. These conflicts are used to more accurately calculate the resulting descendant count of in-mempool ancestors.
[in]vsizeThe sigop-adjusted virtual size of ptx.
Returns
3 possibilities:
  • std::nullopt if all TRUC checks were applied successfully
  • debug string + pointer to a mempool sibling if this transaction would be the second child in a 1-parent-1-child cluster; the caller may consider evicting the specified sibling or return an error with the debug string.
  • debug string + nullptr if this transaction violates some TRUC rule and sibling eviction is not applicable.

Definition at line 164 of file truc_policy.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ TRUC_ANCESTOR_LIMIT

constexpr unsigned int TRUC_ANCESTOR_LIMIT {2}
staticconstexpr

Maximum number of transactions including a TRUC tx and all its mempool ancestors.

Definition at line 27 of file truc_policy.h.

◆ TRUC_CHILD_MAX_VSIZE

constexpr int64_t TRUC_CHILD_MAX_VSIZE {1000}
staticconstexpr

Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed TRUC transaction.

Definition at line 32 of file truc_policy.h.

◆ TRUC_DESCENDANT_LIMIT

constexpr unsigned int TRUC_DESCENDANT_LIMIT {2}
staticconstexpr

Maximum number of transactions including an unconfirmed tx and its descendants.

Definition at line 25 of file truc_policy.h.

◆ TRUC_MAX_VSIZE

constexpr int64_t TRUC_MAX_VSIZE {10000}
staticconstexpr

Maximum sigop-adjusted virtual size of all v3 transactions.

Definition at line 30 of file truc_policy.h.

◆ TRUC_VERSION

constexpr decltype(CTransaction::version) TRUC_VERSION {3}
staticconstexpr

Definition at line 20 of file truc_policy.h.