Bitcoin Core  26.1.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 
13 #include <cstdint>
14 #include <vector>
15 
17 static constexpr uint32_t MAX_PACKAGE_COUNT{25};
22 static constexpr uint32_t MAX_PACKAGE_WEIGHT = 404'000;
23 static_assert(MAX_PACKAGE_WEIGHT >= MAX_STANDARD_TX_WEIGHT);
24 
25 // If a package is to be evaluated, it must be at least as large as the mempool's ancestor/descendant limits,
26 // otherwise transactions that would be individually accepted may be rejected in a package erroneously.
27 // Since a submitted package must be child-with-unconfirmed-parents (all of the transactions are an ancestor
28 // of the child), package limits are ultimately bounded by mempool package limits. Ensure that the
29 // defaults reflect this constraint.
34 
40  PCKG_RESULT_UNSET = 0,
41  PCKG_POLICY,
42  PCKG_TX,
44 };
45 
48 using Package = std::vector<CTransactionRef>;
49 
50 class PackageValidationState : public ValidationState<PackageValidationResult> {};
51 
58 bool CheckPackage(const Package& txns, PackageValidationState& state);
59 
64 bool IsChildWithParents(const Package& package);
65 
69 bool IsChildWithParentsTree(const Package& package);
70 #endif // BITCOIN_POLICY_PACKAGES_H
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
bool CheckPackage(const Package &txns, PackageValidationState &state)
Context-free package policy checks:
Definition: packages.cpp:18
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
Definition: policy.h:65
The package itself is invalid (e.g. too many transactions).
Template for capturing information about block/transaction validation.
Definition: validation.h:91
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:48
bool IsChildWithParentsTree(const Package &package)
Context-free check that a package IsChildWithParents() and none of the parents depend on each other (...
Definition: packages.cpp:92
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_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
Definition: policy.h:59
PackageValidationResult
A "reason" why a package was invalid.
Definition: packages.h:39
At least one tx is invalid.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
Definition: packages.h:17
Initial value. The package has not yet been rejected.
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:75
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:22