Bitcoin Core 28.99.0
P2P Digital Currency
truc_policy.h
Go to the documentation of this file.
1// Copyright (c) 2022 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>
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.
20static 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.
25static constexpr unsigned int TRUC_DESCENDANT_LIMIT{2};
27static constexpr unsigned int TRUC_ANCESTOR_LIMIT{2};
28
30static constexpr int64_t TRUC_MAX_VSIZE{10000};
32static constexpr int64_t TRUC_CHILD_MAX_VSIZE{1000};
33// These limits are within the default ancestor/descendant limits.
36
64std::optional<std::pair<std::string, CTransactionRef>> SingleTRUCChecks(const CTransactionRef& ptx,
65 const CTxMemPool::setEntries& mempool_ancestors,
66 const std::set<Txid>& direct_conflicts,
67 int64_t vsize);
68
90std::optional<std::string> PackageTRUCChecks(const CTransactionRef& ptx, int64_t vsize,
91 const Package& package,
92 const CTxMemPool::setEntries& mempool_ancestors);
93
94#endif // BITCOIN_POLICY_TRUC_POLICY_H
const uint32_t version
Definition: transaction.h:308
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:396
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:50
static constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT_KVB
Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.
Definition: policy.h:61
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
Definition: policy.h:65
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
static constexpr unsigned int TRUC_DESCENDANT_LIMIT
Maximum number of transactions including an unconfirmed tx and its descendants.
Definition: truc_policy.h:25
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.
Definition: truc_policy.cpp:58
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:32
static constexpr decltype(CTransaction::version) TRUC_VERSION
Definition: truc_policy.h:20
static constexpr int64_t TRUC_MAX_VSIZE
Maximum sigop-adjusted virtual size of all v3 transactions.
Definition: truc_policy.h:30
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
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.