Merge bitcoin/bitcoin#22674: validation: mempool validation and submission for packages of 1 child + parents

046e8ff264 [unit test] package submission (glozow)
e12fafda2d [validation] de-duplicate package transactions already in mempool (glozow)
8310d942e0 [packages] add sanity checks for package vs mempool limits (glozow)
be3ff151a1 [validation] full package accept + mempool submission (glozow)
144a29099a [policy] require submitted packages to be child-with-unconfirmed-parents (glozow)
d59ddc5c3d [packages/doc] define and document package rules (glozow)
ba26169f60 [unit test] context-free package checks (glozow)
9b2fdca7f0 [packages] add static IsChildWithParents function (glozow)

Pull request description:

  This is 1 chunk of [Package Mempool Accept](https://gist.github.com/glozow/dc4e9d5c5b14ade7cdfac40f43adb18a); it restricts packages to 1 child with its parents, doesn't allow conflicts, and doesn't have CPFP (yet).  Future PRs (see #22290) will add RBF and CPFP within packages.

ACKs for top commit:
  laanwj:
    Code review ACK 046e8ff264

Tree-SHA512: 37dbba37d527712f8efef71ee05c90a8308992615af35f5e0cfeafc60d859cc792737d125aac526e37742fe7683ac8c155ac24af562426213904333c01260c95
This commit is contained in:
W. J. van der Laan
2021-12-15 20:12:39 +01:00
9 changed files with 567 additions and 21 deletions

View File

@@ -83,6 +83,7 @@ The Bitcoin repo's [root README](/README.md) contains relevant information on th
- [Reduce Memory](reduce-memory.md)
- [Reduce Traffic](reduce-traffic.md)
- [Tor Support](tor.md)
- [Transaction Relay Policy](policy/README.md)
- [ZMQ](zmq.md)
License

10
doc/policy/README.md Normal file
View File

@@ -0,0 +1,10 @@
# Transaction Relay Policy
Policy is a set of validation rules, in addition to consensus, enforced for unconfirmed
transactions.
This documentation is not an exhaustive list of all policy rules.
- [Packages](packages.md)

59
doc/policy/packages.md Normal file
View File

@@ -0,0 +1,59 @@
# Package Mempool Accept
## Definitions
A **package** is an ordered list of transactions, representable by a connected Directed Acyclic
Graph (a directed edge exists between a transaction that spends the output of another transaction).
For every transaction `t` in a **topologically sorted** package, if any of its parents are present
in the package, they appear somewhere in the list before `t`.
A **child-with-unconfirmed-parents** package is a topologically sorted package that consists of
exactly one child and all of its unconfirmed parents (no other transactions may be present).
The last transaction in the package is the child, and its package can be canonically defined based
on the current state: each of its inputs must be available in the UTXO set as of the current chain
tip or some preceding transaction in the package.
## Package Mempool Acceptance Rules
The following rules are enforced for all packages:
* Packages cannot exceed `MAX_PACKAGE_COUNT=25` count and `MAX_PACKAGE_SIZE=101KvB` total size
(#20833)
- *Rationale*: This is already enforced as mempool ancestor/descendant limits. If
transactions in a package are all related, exceeding this limit would mean that the package
can either be split up or it wouldn't pass individual mempool policy.
- Note that, if these mempool limits change, package limits should be reconsidered. Users may
also configure their mempool limits differently.
* Packages must be topologically sorted. (#20833)
* Packages cannot have conflicting transactions, i.e. no two transactions in a package can spend
the same inputs. Packages cannot have duplicate transactions. (#20833)
* No transaction in a package can conflict with a mempool transaction. BIP125 Replace By Fee is
currently disabled for packages. (#20833)
- Package RBF may be enabled in the future.
* When packages are evaluated against ancestor/descendant limits, the union of all transactions'
descendants and ancestors is considered. (#21800)
- *Rationale*: This is essentially a "worst case" heuristic intended for packages that are
heavily connected, i.e. some transaction in the package is the ancestor or descendant of all
the other transactions.
The following rules are only enforced for packages to be submitted to the mempool (not enforced for
test accepts):
* Packages must be child-with-unconfirmed-parents packages. This also means packages must contain at
least 2 transactions. (#22674)
- *Rationale*: This allows for fee-bumping by CPFP. Allowing multiple parents makes it possible
to fee-bump a batch of transactions. Restricting packages to a defined topology is easier to
reason about and simplifies the validation logic greatly.
- Warning: Batched fee-bumping may be unsafe for some use cases. Users and application developers
should take caution if utilizing multi-parent packages.