2021-02-11 09:50:42 -08:00
|
|
|
// Copyright (c) 2021 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_POLICY_PACKAGES_H
|
|
|
|
#define BITCOIN_POLICY_PACKAGES_H
|
|
|
|
|
2022-05-31 13:30:23 +02:00
|
|
|
#include <consensus/consensus.h>
|
2021-02-11 09:50:42 -08:00
|
|
|
#include <consensus/validation.h>
|
2021-05-26 18:08:55 +01:00
|
|
|
#include <policy/policy.h>
|
2021-02-11 09:50:42 -08:00
|
|
|
#include <primitives/transaction.h>
|
|
|
|
|
2022-05-31 13:30:23 +02:00
|
|
|
#include <cstdint>
|
2021-02-11 09:50:42 -08:00
|
|
|
#include <vector>
|
|
|
|
|
2021-04-05 11:13:27 -07:00
|
|
|
/** Default maximum number of transactions in a package. */
|
|
|
|
static constexpr uint32_t MAX_PACKAGE_COUNT{25};
|
|
|
|
/** Default maximum total virtual size of transactions in a package in KvB. */
|
|
|
|
static constexpr uint32_t MAX_PACKAGE_SIZE{101};
|
2021-05-26 18:08:55 +01:00
|
|
|
static_assert(MAX_PACKAGE_SIZE * WITNESS_SCALE_FACTOR * 1000 >= MAX_STANDARD_TX_WEIGHT);
|
2021-04-05 11:13:27 -07:00
|
|
|
|
2021-02-11 09:50:42 -08:00
|
|
|
/** A "reason" why a package was invalid. It may be that one or more of the included
|
|
|
|
* transactions is invalid or the package itself violates our rules.
|
|
|
|
* We don't distinguish between consensus and policy violations right now.
|
|
|
|
*/
|
|
|
|
enum class PackageValidationResult {
|
|
|
|
PCKG_RESULT_UNSET = 0, //!< Initial value. The package has not yet been rejected.
|
|
|
|
PCKG_POLICY, //!< The package itself is invalid (e.g. too many transactions).
|
|
|
|
PCKG_TX, //!< At least one tx is invalid.
|
2022-01-07 16:55:53 +00:00
|
|
|
PCKG_MEMPOOL_ERROR, //!< Mempool logic error.
|
2021-02-11 09:50:42 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A package is an ordered list of transactions. The transactions cannot conflict with (spend the
|
|
|
|
* same inputs as) one another. */
|
|
|
|
using Package = std::vector<CTransactionRef>;
|
|
|
|
|
|
|
|
class PackageValidationState : public ValidationState<PackageValidationResult> {};
|
|
|
|
|
2021-06-02 16:19:29 +01:00
|
|
|
/** Context-free package policy checks:
|
|
|
|
* 1. The number of transactions cannot exceed MAX_PACKAGE_COUNT.
|
|
|
|
* 2. The total virtual size cannot exceed MAX_PACKAGE_SIZE.
|
|
|
|
* 3. If any dependencies exist between transactions, parents must appear before children.
|
|
|
|
* 4. Transactions cannot conflict, i.e., spend the same inputs.
|
|
|
|
*/
|
|
|
|
bool CheckPackage(const Package& txns, PackageValidationState& state);
|
|
|
|
|
2021-07-16 10:29:11 +01:00
|
|
|
/** Context-free check that a package is exactly one child and its parents; not all parents need to
|
|
|
|
* be present, but the package must not contain any transactions that are not the child's parents.
|
|
|
|
* It is expected to be sorted, which means the last transaction must be the child.
|
|
|
|
*/
|
|
|
|
bool IsChildWithParents(const Package& package);
|
|
|
|
|
2021-02-11 09:50:42 -08:00
|
|
|
#endif // BITCOIN_POLICY_PACKAGES_H
|