Skip to content

Commit 23afc5f

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23711: docs: RBF policy and mempool limit exemptions
82858ba [doc] CPFP carve out and single-conflict RBF exemption (glozow) 1fd49eb [doc] clarify RBF difference from BIP125 (glozow) 919ae8b [doc] current rbf policy (glozow) Pull request description: Since RBF was first implemented and BIP125 was written, our code has changed, people have highlighted implementation differences, and some people have proposed further changes to it. Many people seem to support the idea of documenting our _current_ RBF policy as it stands today. As the ancestor/descendant limit carve-out exemptions are very related to RBF, it seemed appropriate to group them with this PR. Related to #22806 - it seems that these policies are the most confusing for people, or at least the most documentation-requested. ACKs for top commit: dunxen: ACK 82858ba t-bast: ACK bitcoin/bitcoin@82858ba, thanks @glozow! darosior: re-ACK 82858ba ariard: ACK 82858ba Tree-SHA512: 5d296537cce3488c18179c0aa76c739ca02fdc424e5aa17129b4cdd0d057358f86bcc1e92a9857bd2c60495f834fe9d9406d1a9f8ac5cfc8f0f4f4c27ec4f8e1
2 parents d1dc6b8 + 82858ba commit 23afc5f

File tree

4 files changed

+143
-4
lines changed

4 files changed

+143
-4
lines changed

doc/bips.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BIPs that are implemented by Bitcoin Core (up-to-date up to **v22.0**):
3232
* [`BIP 111`](https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki): `NODE_BLOOM` service bit added, and enforced for all peer versions as of **v0.13.0** ([PR #6579](https://github.com/bitcoin/bitcoin/pull/6579) and [PR #6641](https://github.com/bitcoin/bitcoin/pull/6641)).
3333
* [`BIP 112`](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki): The CHECKSEQUENCEVERIFY opcode has been implemented since **v0.12.1** ([PR #7524](https://github.com/bitcoin/bitcoin/pull/7524)), and has been *buried* since **v0.19.0** ([PR #16060](https://github.com/bitcoin/bitcoin/pull/16060)).
3434
* [`BIP 113`](https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki): Median time past lock-time calculations have been implemented since **v0.12.1** ([PR #6566](https://github.com/bitcoin/bitcoin/pull/6566)), and has been *buried* since **v0.19.0** ([PR #16060](https://github.com/bitcoin/bitcoin/pull/16060)).
35-
* [`BIP 125`](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki): Opt-in full replace-by-fee signaling honoured in mempool and mining as of **v0.12.0** ([PR 6871](https://github.com/bitcoin/bitcoin/pull/6871)). Enabled by default in the wallet GUI as of **v0.18.1** ([PR #11605](https://github.com/bitcoin/bitcoin/pull/11605))
35+
* [`BIP 125`](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki): Opt-in full replace-by-fee signaling partially implemented. See doc/policy/mempool-replacements.md.
3636
* [`BIP 130`](https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki): direct headers announcement is negotiated with peer versions `>=70012` as of **v0.12.0** ([PR 6494](https://github.com/bitcoin/bitcoin/pull/6494)).
3737
* [`BIP 133`](https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki): feefilter messages are respected and sent for peer versions `>=70013` as of **v0.13.0** ([PR 7542](https://github.com/bitcoin/bitcoin/pull/7542)).
3838
* [`BIP 141`](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki): Segregated Witness (Consensus Layer) as of **v0.13.0** ([PR 8149](https://github.com/bitcoin/bitcoin/pull/8149)), defined for mainnet as of **v0.13.1** ([PR 8937](https://github.com/bitcoin/bitcoin/pull/8937)), and *buried* since **v0.19.0** ([PR #16060](https://github.com/bitcoin/bitcoin/pull/16060)).

doc/policy/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Transaction Relay Policy
22

3-
Policy is a set of validation rules, in addition to consensus, enforced for unconfirmed
4-
transactions.
3+
**Policy** (Mempool or Transaction Relay Policy) is the node's set of validation rules, in addition
4+
to consensus, enforced for unconfirmed transactions before submitting them to the mempool. These
5+
rules are local to the node and configurable (e.g. `-minrelaytxfee`, `-limitancestorsize`,
6+
`-incrementalRelayFee`). Policy may include restrictions on the transaction itself, the transaction
7+
in relation to the current chain tip, and the transaction in relation to the node's mempool
8+
contents. Policy is *not* applied to transactions in blocks.
59

610
This documentation is not an exhaustive list of all policy rules.
711

12+
- [Mempool Limits](mempool-limits.md)
13+
- [Mempool Replacements](mempool-replacements.md)
814
- [Packages](packages.md)
915

10-

doc/policy/mempool-limits.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Mempool Limits
2+
3+
## Definitions
4+
5+
Given any two transactions Tx0 and Tx1 where Tx1 spends an output of Tx0,
6+
Tx0 is a *parent* of Tx1 and Tx1 is a *child* of Tx0.
7+
8+
A transaction's *ancestors* include, recursively, its parents, the parents of its parents, etc.
9+
A transaction's *descendants* include, recursively, its children, the children of its children, etc.
10+
11+
A mempool entry's *ancestor count* is the total number of in-mempool (unconfirmed) transactions in
12+
its ancestor set, including itself.
13+
A mempool entry's *descendant count* is the total number of in-mempool (unconfirmed) transactions in
14+
its descendant set, including itself.
15+
16+
A mempool entry's *ancestor size* is the aggregated virtual size of in-mempool (unconfirmed)
17+
transactions in its ancestor set, including itself.
18+
A mempool entry's *descendant size* is the aggregated virtual size of in-mempool (unconfirmed)
19+
transactions in its descendant set, including itself.
20+
21+
Transactions submitted to the mempool must not exceed the ancestor and descendant limits (aka
22+
mempool *package limits*) set by the node (see `-limitancestorcount`, `-limitancestorsize`,
23+
`-limitdescendantcount`, `-limitdescendantsize`).
24+
25+
## Exemptions
26+
27+
### CPFP Carve Out
28+
29+
**CPFP Carve Out** if a transaction candidate for submission to the
30+
mempool would cause some mempool entry to exceed its descendant limits, an exemption is made if all
31+
of the following conditions are met:
32+
33+
1. The candidate transaction is no more than 10,000 virtual bytes.
34+
35+
2. The candidate transaction has an ancestor count of 2 (itself and exactly 1 ancestor).
36+
37+
3. The in-mempool transaction's descendant count, including the candidate transaction, would only
38+
exceed the limit by 1.
39+
40+
*Rationale*: this rule was introduced to prevent pinning by domination of a transaction's descendant
41+
limits in two-party contract protocols such as LN. Also see the [mailing list
42+
post](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-November/016518.html).
43+
44+
This rule was introduced in [PR #15681](https://github.com/bitcoin/bitcoin/pull/15681).
45+
46+
### Single-Conflict RBF Carve Out
47+
48+
When a candidate transaction for submission to the mempool would replace mempool entries, it may
49+
also decrease the descendant count of other mempool entries. Since ancestor/descendant limits are
50+
calculated prior to removing the would-be-replaced transactions, they may be overestimated.
51+
52+
An exemption is given for a candidate transaction that would replace mempool transactions and meets
53+
all of the following conditions:
54+
55+
1. The candidate transaction has exactly 1 directly conflicting transaction.
56+
57+
2. The candidate transaction does not spend any unconfirmed inputs that are not also spent by the
58+
directly conflicting transaction.
59+
60+
The following discounts are given to account for the would-be-replaced transaction(s):
61+
62+
1. The descendant count limit is temporarily increased by 1.
63+
64+
2. The descendant size limit temporarily is increased by the virtual size of the to-be-replaced
65+
directly conflicting transaction.

doc/policy/mempool-replacements.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Mempool Replacements
2+
3+
## Current Replace-by-Fee Policy
4+
5+
A transaction conflicts with an in-mempool transaction ("directly conflicting transaction") if they
6+
spend one or more of the same inputs. A transaction may conflict with multiple in-mempool
7+
transactions.
8+
9+
A transaction ("replacement transaction") may replace its directly conflicting transactions and
10+
their in-mempool descendants (together, "original transactions") if, in addition to passing all
11+
other consensus and policy rules, each of the following conditions are met:
12+
13+
1. The directly conflicting transactions all signal replaceability explicitly. A transaction is
14+
signaling replaceability if any of its inputs have an nSequence number less than (0xffffffff - 1).
15+
16+
*Rationale*: See [BIP125
17+
explanation](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki#motivation).
18+
19+
2. The replacement transaction only include an unconfirmed input if that input was included in
20+
one of the directly conflicting transactions. An unconfirmed input spends an output from a
21+
currently-unconfirmed transaction.
22+
23+
*Rationale*: When RBF was originally implemented, the mempool did not keep track of
24+
ancestor feerates yet. This rule was suggested as a temporary restriction.
25+
26+
3. The replacement transaction pays an absolute fee of at least the sum paid by the original
27+
transactions.
28+
29+
*Rationale*: Only requiring the replacement transaction to have a higher feerate could allow an
30+
attacker to bypass node minimum relay feerate requirements and cause the network to repeatedly
31+
relay slightly smaller replacement transactions without adding any more fees. Additionally, if
32+
any of the original transactions would be included in the next block assembled by an economically
33+
rational miner, a replacement policy allowing the replacement transaction to decrease the absolute
34+
fees in the next block would be incentive-incompatible.
35+
36+
4. The additional fees (difference between absolute fee paid by the replacement transaction and the
37+
sum paid by the original transactions) pays for the replacement transaction's bandwidth at or
38+
above the rate set by the node's incremental relay feerate. For example, if the incremental relay
39+
feerate is 1 satoshi/vB and the replacement transaction is 500 virtual bytes total, then the
40+
replacement pays a fee at least 500 satoshis higher than the sum of the original transactions.
41+
42+
*Rationale*: Try to prevent DoS attacks where an attacker causes the network to repeatedly relay
43+
transactions each paying a tiny additional amount in fees, e.g. just 1 satoshi.
44+
45+
5. The number of original transactions does not exceed 100. More precisely, the sum of all
46+
directly conflicting transactions' descendant counts (number of transactions inclusive of itself
47+
and its descendants) must not exceed 100; it is possible that this overestimates the true number
48+
of original transactions.
49+
50+
*Rationale*: Try to prevent DoS attacks where an attacker is able to easily occupy and flush out
51+
significant portions of the node's mempool using replacements with multiple directly conflicting
52+
transactions, each with large descendant sets.
53+
54+
This set of rules is similar but distinct from BIP125.
55+
56+
## History
57+
58+
* Opt-in full replace-by-fee (without inherited signaling) honoured in mempool and mining as of
59+
**v0.12.0** ([PR 6871](https://github.com/bitcoin/bitcoin/pull/6871)).
60+
61+
* [BIP125](https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki) defined based on
62+
Bitcoin Core implementation.
63+
64+
* The incremental relay feerate used to calculate the required additional fees is distinct from
65+
`minRelayTxFee` and configurable using `-incrementalrelayfee`
66+
([PR #9380](https://github.com/bitcoin/bitcoin/pull/9380)).
67+
68+
* RBF enabled by default in the wallet GUI as of **v0.18.1** ([PR
69+
#11605](https://github.com/bitcoin/bitcoin/pull/11605)).

0 commit comments

Comments
 (0)