12#include <unordered_set>
15 const size_t package_count = txns.size();
21 "package-too-many-transactions");
24 const int64_t total_size = std::accumulate(
25 txns.cbegin(), txns.cend(), 0, [](int64_t
sum,
const auto &tx) {
26 return sum + GetVirtualTransactionSize(*tx);
40 std::unordered_set<TxId, SaltedTxIdHasher> later_txids;
41 std::transform(txns.cbegin(), txns.cend(),
42 std::inserter(later_txids, later_txids.end()),
43 [](
const auto &tx) { return tx->GetId(); });
47 if (later_txids.size() != txns.size()) {
49 "package-contains-duplicates");
52 for (
const auto &tx : txns) {
53 for (
const auto &input : tx->vin) {
54 if (later_txids.find(input.prevout.GetTxId()) !=
58 "package-not-sorted");
61 later_txids.erase(tx->GetId());
66 std::unordered_set<COutPoint, SaltedOutpointHasher> inputs_seen;
67 for (
const auto &tx : txns) {
68 for (
const auto &input : tx->vin) {
69 if (inputs_seen.find(input.prevout) != inputs_seen.end()) {
72 "conflict-in-package");
79 std::transform(tx->vin.cbegin(), tx->vin.cend(),
80 std::inserter(inputs_seen, inputs_seen.end()),
81 [](
const auto &input) { return input.prevout; });
87 assert(std::all_of(package.cbegin(), package.cend(),
88 [](
const auto &tx) { return tx != nullptr; }));
89 if (package.size() < 2) {
95 const auto &child = package.back();
96 std::unordered_set<TxId, SaltedTxIdHasher> input_txids;
97 std::transform(child->vin.cbegin(), child->vin.cend(),
98 std::inserter(input_txids, input_txids.end()),
99 [](
const auto &input) { return input.prevout.GetTxId(); });
103 return std::all_of(package.cbegin(), package.cend() - 1,
104 [&input_txids](
const auto &ptx) {
105 return input_txids.count(ptx->GetId()) > 0;
113 std::unordered_set<TxId, SaltedTxIdHasher> parent_txids;
114 std::transform(package.cbegin(), package.cend() - 1,
115 std::inserter(parent_txids, parent_txids.end()),
116 [](
const auto &ptx) { return ptx->GetId(); });
119 package.cbegin(), package.cend() - 1, [&](
const auto &ptx) {
120 for (const auto &input : ptx->vin) {
121 if (parent_txids.count(input.prevout.GetTxId()) > 0) {
131 std::vector<TxId> txids_copy;
132 std::transform(package.cbegin(), package.cend(),
133 std::back_inserter(txids_copy),
134 [](
const auto &tx) { return tx->GetId(); });
137 std::sort(txids_copy.begin(), txids_copy.end(),
138 [](
const auto &lhs,
const auto &rhs) { return lhs < rhs; });
142 for (
const auto &txid : txids_copy) {
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetSHA256()
Compute the SHA256 hash of all data written to this object.
bool Invalid(Result result, const std::string &reject_reason="", const std::string &debug_message="")
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...
bool IsChildWithParentsTree(const Package &package)
Context-free check that a package IsChildWithParents() and none of the parents depend on each other (...
bool CheckPackage(const Package &txns, PackageValidationState &state)
Context-free package policy checks:
uint256 GetPackageHash(const Package &package)
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
static constexpr uint32_t MAX_PACKAGE_SIZE
Default maximum total size of transactions in a package in KB.
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).