Bitcoin Core  27.99.0
P2P Digital Currency
packages.h
Go to the documentation of this file.
1 // Copyright (c) 2021-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_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;
26 
27 // If a package is to be evaluated, it must be at least as large as the mempool's ancestor/descendant limits,
28 // otherwise transactions that would be individually accepted may be rejected in a package erroneously.
29 // Since a submitted package must be child-with-unconfirmed-parents (all of the transactions are an ancestor
30 // of the child), package limits are ultimately bounded by mempool package limits. Ensure that the
31 // defaults reflect this constraint.
36 
42  PCKG_RESULT_UNSET = 0,
43  PCKG_POLICY,
44  PCKG_TX,
46 };
47 
50 using Package = std::vector<CTransactionRef>;
51 
52 class PackageValidationState : public ValidationState<PackageValidationResult> {};
53 
60 bool IsTopoSortedPackage(const Package& txns);
61 
71 bool IsConsistentPackage(const Package& txns);
72 
79 bool IsWellFormedPackage(const Package& txns, PackageValidationState& state, bool require_sorted);
80 
85 bool IsChildWithParents(const Package& package);
86 
90 bool IsChildWithParentsTree(const Package& package);
91 #endif // BITCOIN_POLICY_PACKAGES_H
Template for capturing information about block/transaction validation.
Definition: validation.h:93
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
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
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:50
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
bool IsConsistentPackage(const Package &txns)
Checks that these transactions don't conflict, i.e., spend the same prevout.
Definition: packages.cpp:52
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
Definition: packages.h:19
bool IsWellFormedPackage(const Package &txns, PackageValidationState &state, bool require_sorted)
Context-free package policy checks:
Definition: packages.cpp:79
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
PackageValidationResult
A "reason" why a package was invalid.
Definition: packages.h:41
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
@ PCKG_RESULT_UNSET
Initial value. The package has not yet been rejected.
@ PCKG_MEMPOOL_ERROR
Mempool logic error.
@ PCKG_TX
At least one tx is invalid.
bool IsTopoSortedPackage(const Package &txns)
If any direct dependencies exist between transactions (i.e.
Definition: packages.cpp:43
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_LIMIT
Default for -limitdescendantcount, max number of in-mempool descendants.
Definition: policy.h:63
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
Definition: policy.h:65
static constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
Definition: policy.h:27
static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
Definition: policy.h:59