Bitcoin Core  31.0.0
P2P Digital Currency
packages.h
Go to the documentation of this file.
1 // Copyright (c) 2021-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_PACKAGES_H
6 #define BITCOIN_POLICY_PACKAGES_H
7 
8 #include <consensus/consensus.h>
9 #include <consensus/validation.h>
10 #include <policy/policy.h>
11 #include <primitives/transaction.h>
12 #include <util/hasher.h>
13 
14 #include <cstdint>
15 #include <unordered_set>
16 #include <vector>
17 
19 static constexpr uint32_t MAX_PACKAGE_COUNT{25};
24 static constexpr uint32_t MAX_PACKAGE_WEIGHT = 404'000;
25 static_assert(MAX_PACKAGE_WEIGHT >= MAX_STANDARD_TX_WEIGHT);
26 
27 // Packages are part of a single cluster, so ensure that the package limits are
28 // set within the mempool's cluster size limits.
31 
37  PCKG_RESULT_UNSET = 0,
38  PCKG_POLICY,
39  PCKG_TX,
41 };
42 
45 using Package = std::vector<CTransactionRef>;
46 
47 class PackageValidationState : public ValidationState<PackageValidationResult> {};
48 
55 bool IsTopoSortedPackage(const Package& txns);
56 
66 bool IsConsistentPackage(const Package& txns);
67 
74 bool IsWellFormedPackage(const Package& txns, PackageValidationState& state);
75 
80 bool IsChildWithParents(const Package& package);
81 
85 bool IsChildWithParentsTree(const Package& package);
86 
90 uint256 GetPackageHash(const std::vector<CTransactionRef>& transactions);
91 
92 #endif // BITCOIN_POLICY_PACKAGES_H
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
The package itself is invalid (e.g. too many transactions).
Template for capturing information about block/transaction validation.
Definition: validation.h:75
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:45
bool IsChildWithParentsTree(const Package &package)
Context-free check that a package IsChildWithParents() and none of the parents depend on each other (...
Definition: packages.cpp:136
bool IsConsistentPackage(const Package &txns)
Checks that these transactions don&#39;t conflict, i.e., spend the same prevout.
Definition: packages.cpp:52
PackageValidationResult
A "reason" why a package was invalid.
Definition: packages.h:36
At least one tx is invalid.
bool IsWellFormedPackage(const Package &txns, PackageValidationState &state)
Context-free package policy checks:
Definition: packages.cpp:79
256-bit opaque blob.
Definition: uint256.h:195
static constexpr unsigned int DEFAULT_CLUSTER_SIZE_LIMIT_KVB
Maximum size of cluster in virtual kilobytes.
Definition: policy.h:73
static constexpr unsigned int DEFAULT_CLUSTER_LIMIT
Maximum number of transactions per cluster (default)
Definition: policy.h:71
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
Definition: packages.h:19
bool IsTopoSortedPackage(const Package &txns)
If any direct dependencies exist between transactions (i.e.
Definition: packages.cpp:43
Initial value. The package has not yet been rejected.
uint256 GetPackageHash(const std::vector< CTransactionRef > &transactions)
Get the hash of the concatenated wtxids of transactions, with wtxids treated as a little-endian numbe...
Definition: packages.cpp:151
bool IsChildWithParents(const Package &package)
Context-free check that a package is exactly one child and its parents; not all parents need to be pr...
Definition: packages.cpp:119
static constexpr uint32_t MAX_PACKAGE_WEIGHT
Default maximum total weight of transactions in a package in weight to allow for context-less checks...
Definition: packages.h:24