Bitcoin Core  31.0.0
P2P Digital Currency
truc_policy.h
Go to the documentation of this file.
1 // Copyright (c) 2022-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_POLICY_TRUC_POLICY_H
6 #define BITCOIN_POLICY_TRUC_POLICY_H
7 
8 #include <consensus/amount.h>
9 #include <policy/packages.h>
10 #include <policy/policy.h>
11 #include <primitives/transaction.h>
12 #include <txmempool.h>
13 #include <util/result.h>
14 
15 #include <set>
16 #include <string>
17 
18 // This module enforces rules for BIP 431 TRUC transactions which help make
19 // RBF abilities more robust. A transaction with version=3 is treated as TRUC.
20 static constexpr decltype(CTransaction::version) TRUC_VERSION{3};
21 
22 // TRUC only allows 1 parent and 1 child when unconfirmed. This translates to a descendant set size
23 // of 2 and ancestor set size of 2.
25 static constexpr unsigned int TRUC_DESCENDANT_LIMIT{2};
27 static constexpr unsigned int TRUC_ANCESTOR_LIMIT{2};
28 
30 static constexpr int64_t TRUC_MAX_VSIZE{10000};
33 static constexpr int64_t TRUC_CHILD_MAX_VSIZE{1000};
35 // These limits are within the default cluster limits.
37 
66 std::optional<std::pair<std::string, CTransactionRef>> SingleTRUCChecks(const CTxMemPool& pool, const CTransactionRef& ptx,
67  const std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>& mempool_parents,
68  const std::set<Txid>& direct_conflicts,
69  int64_t vsize) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
70 
92 std::optional<std::string> PackageTRUCChecks(const CTxMemPool& pool, const CTransactionRef& ptx, int64_t vsize,
93  const Package& package,
94  const std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>& mempool_parents) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
95 
96 #endif // BITCOIN_POLICY_TRUC_POLICY_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
static constexpr int64_t TRUC_CHILD_MAX_VSIZE
Maximum sigop-adjusted virtual size of a tx which spends from an unconfirmed TRUC transaction...
Definition: truc_policy.h:33
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:45
static constexpr int64_t TRUC_MAX_VSIZE
Maximum sigop-adjusted virtual size of all v3 transactions.
Definition: truc_policy.h:30
static constexpr int64_t TRUC_MAX_WEIGHT
Definition: truc_policy.h:31
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) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
Must be called for every transaction, even if not TRUC.
std::optional< std::string > PackageTRUCChecks(const CTxMemPool &pool, const CTransactionRef &ptx, int64_t vsize, const Package &package, const std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > &mempool_parents) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
Must be called for every transaction that is submitted within a package, even if not TRUC...
Definition: truc_policy.cpp:57
static decltype(CTransaction::version) constexpr TRUC_VERSION
Definition: truc_policy.h:20
static constexpr int64_t TRUC_CHILD_MAX_WEIGHT
Definition: truc_policy.h:34
static constexpr unsigned int TRUC_ANCESTOR_LIMIT
Maximum number of transactions including a TRUC tx and all its mempool ancestors. ...
Definition: truc_policy.h:27
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:186
static constexpr unsigned int DEFAULT_CLUSTER_SIZE_LIMIT_KVB
Maximum size of cluster in virtual kilobytes.
Definition: policy.h:73
static constexpr unsigned int TRUC_DESCENDANT_LIMIT
Maximum number of transactions including an unconfirmed tx and its descendants.
Definition: truc_policy.h:25
const uint32_t version
Definition: transaction.h:293