Skip to content

Commit f7a3b14

Browse files
authored
add CPFP, RBF and netowrk propoagation topics (#83)
1 parent f095288 commit f7a3b14

File tree

8 files changed

+299
-16
lines changed

8 files changed

+299
-16
lines changed

decoding/cpfp.mdx

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: "Child Pay For Parent (CPFP)"
3+
date: 2024-01-25T15:32:14Z
4+
lastmod: "2024-07-26"
5+
draft: false
6+
category: Transactions
7+
layout: TopicBanner
8+
order: 4
9+
icon: "FaClipboardList"
10+
images: ["/decoding-bitcoin/static/images/topics/thumbnails/musig-thumbnail.webp"]
11+
parent: "fee-calculation"
12+
---
13+
14+
Imagine receiving bitcoin but the transaction is stuck in the mempool.
15+
The sender used a fee that's too low, and miners aren't picking it up.
16+
17+
<div className="dark:hidden w-full rounded-lg">
18+
<SvgDisplay
19+
src="/decoding-bitcoin/static/images/topics/transactions/fees/cpfp-1.svg"
20+
width="100%"
21+
height="auto"
22+
/>
23+
</div>
24+
<div className="hidden dark:block w-full rounded-lg">
25+
<SvgDisplay
26+
src="/decoding-bitcoin/static/images/topics/transactions/fees/cpfp-1.svg"
27+
width="100%"
28+
height="auto"
29+
/>
30+
</div>
31+
32+
What can you do? This is where Child Pays For Parent (CPFP) comes in.
33+
34+
35+
## What is CPFP?
36+
37+
CPFP is a fee-bumping strategy where the recipient of an unconfirmed transaction creates a new transaction (child) that spends the pending funds and includes a high enough fee to incentivize miners to confirm both transactions together.
38+
39+
40+
## How Does CPFP Work?
41+
42+
Let's break it down with an example:
43+
44+
1. Alice sends 1 BTC to Bob with a very low fee
45+
2. The transaction gets stuck in the mempool because miners ignore low-fee transactions
46+
3. Bob creates a new transaction (child) spending the unconfirmed bitcoin
47+
4. Bob attaches a high fee to the child transaction
48+
5. Miners see they can collect both fees by including both transactions
49+
6. Both transactions get confirmed in the next block
50+
51+
52+
<div className="dark:hidden w-full rounded-lg">
53+
<SvgDisplay
54+
src="/decoding-bitcoin/static/images/topics/transactions/fees/cpfp-2.svg"
55+
width="100%"
56+
height="auto"
57+
/>
58+
</div>
59+
<div className="hidden dark:block w-full rounded-lg">
60+
<SvgDisplay
61+
src="/decoding-bitcoin/static/images/topics/transactions/fees/cpfp-2.svg"
62+
width="100%"
63+
height="auto"
64+
/>
65+
</div>
66+
67+
## Technical Details
68+
69+
CPFP works because of two key Bitcoin concepts:
70+
71+
1. **UTXO Model**: Bitcoin allows spending unconfirmed outputs, enabling the creation of child transactions
72+
2. **Mempool Package Evaluation**: Miners evaluate related transactions as a package, considering their combined size and fees
73+
74+
### Fee Calculation
75+
76+
The effective fee rate for a CPFP package is:
77+
78+
<div className="text-center my-4 text-orange-500">
79+
$$\text{Effective Fee Rate} = \frac{\text{Parent Fee + Child Fee}}{\text{Parent Size + Child Size}}$$
80+
</div>
81+
82+
CPFP is particularly useful when:
83+
- You receive a transaction with too low fees
84+
- The sender didn't enable RBF (Replace-By-Fee)
85+
- You need urgent confirmation of incoming funds
86+
87+
## Limitations
88+
89+
While powerful, CPFP has some constraints:
90+
- Only the recipient can initiate CPFP
91+
- Requires enough funds to cover the new transaction fee
92+
- Some wallets don't support CPFP natively
93+
- May not work during extreme network congestion

decoding/fee-calculation.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ layout: TopicBanner
88
order: 306
99
icon: "FaClipboardList"
1010
images: ["/decoding-bitcoin/static/images/topics/thumbnails/transaction-module/fees-thumbnail-feecalculation.jpg"]
11-
children: ["transaction-weight", "blocksize-blockweight", "fee-rate", "rbf"]
11+
children: ["transaction-weight", "blocksize-blockweight", "fee-rate", "rbf", "cpfp"]
1212
---
1313

1414
## Topics:

decoding/network-propagation.mdx

-13
This file was deleted.

decoding/rbf.mdx

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "RBF"
2+
title: "Replace-By-Fee (RBF)"
33
date: 2024-01-25T15:32:14Z
44
lastmod: "2024-07-26"
55
draft: false
@@ -11,4 +11,42 @@ images: ["/decoding-bitcoin/static/images/topics/thumbnails/musig-thumbnail.webp
1111
parent: "fee-calculation"
1212
---
1313

14-
(coming soon)
14+
15+
Imagine you send a Bitcoin transaction to your friend. You eagerly wait for it to be confirmed, but it gets stuck in the mempool.
16+
17+
Why? **Because the fee you set was too low**, and miners aren't interested in including it in a block.
18+
19+
## The Problem
20+
21+
Your transaction is sitting in the mempool, unconfirmed for 48 hours. Frustrated, you wonder why it's taking so long. The answer is simple: your transaction fee is too low, and no miner is picking it up.
22+
23+
<div className="dark:hidden w-full rounded-lg">
24+
<SvgDisplay
25+
src="/decoding-bitcoin/static/images/topics/topics/transactions/fees/rbf-1.jpg"
26+
width="100%"
27+
height="auto"
28+
/>
29+
</div>
30+
<div className="hidden dark:block w-full rounded-lg">
31+
<SvgDisplay
32+
src="/decoding-bitcoin/static/images/topics/transactions/fees/rbf-1.jpg"
33+
width="100%"
34+
height="auto"
35+
/>
36+
</div>
37+
38+
## The Solution: RBF
39+
40+
To fix this, you can use Replace-By-Fee (RBF). RBF allows you to replace your stuck transaction with a new one that offers a higher fee, making it more attractive to miners.
41+
42+
## How Does RBF Work?
43+
44+
To increase the fee, you create a conflicting version of the transaction. This new transaction spends at least one of the same UTXOs as the original transaction you want to replace.
45+
46+
By doing this, you signal to the network that your transaction can be replaced by one with a higher fee.
47+
48+
## Types of RBF
49+
50+
1. **Opt-in RBF**: Here, the transaction must specify and signal to miners that it can be replaced by a higher fee transaction. This is done by setting the `nSequence` to a value below `0xffffffff`.
51+
52+
2. **Full RBF**: Any unconfirmed transaction can be replaced without signaling. This method offers more flexibility but may face network policy restrictions.

0 commit comments

Comments
 (0)