11 #include <unordered_set>
14 const size_t package_count = txns.size();
20 "package-too-many-transactions");
23 const int64_t total_size = std::accumulate(
24 txns.cbegin(), txns.cend(), 0, [](int64_t
sum,
const auto &tx) {
25 return sum + GetVirtualTransactionSize(*tx);
39 std::unordered_set<TxId, SaltedTxIdHasher> later_txids;
40 std::transform(txns.cbegin(), txns.cend(),
41 std::inserter(later_txids, later_txids.end()),
42 [](
const auto &tx) { return tx->GetId(); });
43 for (
const auto &tx : txns) {
44 for (
const auto &input : tx->vin) {
45 if (later_txids.find(input.prevout.GetTxId()) !=
49 "package-not-sorted");
52 later_txids.erase(tx->GetId());
57 std::unordered_set<COutPoint, SaltedOutpointHasher> inputs_seen;
58 for (
const auto &tx : txns) {
59 for (
const auto &input : tx->vin) {
60 if (inputs_seen.find(input.prevout) != inputs_seen.end()) {
63 "conflict-in-package");
70 std::transform(tx->vin.cbegin(), tx->vin.cend(),
71 std::inserter(inputs_seen, inputs_seen.end()),
72 [](
const auto &input) { return input.prevout; });
78 assert(std::all_of(package.cbegin(), package.cend(),
79 [](
const auto &tx) { return tx != nullptr; }));
80 if (package.size() < 2) {
86 const auto &child = package.back();
87 std::unordered_set<TxId, SaltedTxIdHasher> input_txids;
88 std::transform(child->vin.cbegin(), child->vin.cend(),
89 std::inserter(input_txids, input_txids.end()),
90 [](
const auto &input) { return input.prevout.GetTxId(); });
94 return std::all_of(package.cbegin(), package.cend() - 1,
95 [&input_txids](
const auto &ptx) {
96 return input_txids.count(ptx->GetId()) > 0;
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 CheckPackage(const Package &txns, PackageValidationState &state)
Context-free package policy checks:
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).