TeachMeBitcoin

Child Pays For Parent (CPFP)

From TeachMeBitcoin, the free encyclopedia โฑ๏ธ 4 min read

How Child Pays For Parent (CPFP) Works: Mathematical Fee-Bumping and Miner Scoring

When a transaction is broadcast with a fee rate that is too low to satisfy current network demand, it can become stuck indefinitely in mempools. Child Pays For Parent (CPFP) is a fee-bumping technique that allows a recipient (or a sender spending a change output) to accelerate the stuck parent transaction by creating a high-fee child transaction.

This guide details the mathematical scoring mechanisms miners use to evaluate unconfirmed packages and select them for inclusion in candidate blocks.


๐Ÿ“ˆ 1. The Core Mining Dilemma

Miners compile transactions into candidate blocks to maximize their fee revenue. However, a miner cannot select a child transaction for a block unless all of its ancestor transactions are also included in that block.

If a parent transaction $T_P$ has a low feerate ($1\text{ sat/vB}$) and its child transaction $T_C$ has an extremely high feerate ($100\text{ sat/vB}$), the miner cannot simply mine $T_C$ and pocket the premium. To capture the fee on $T_C$, they must also mine $T_P$.

To solve this dependency problem, mining algorithms evaluate transactions not in isolation, but as packages of ancestors.


๐Ÿงฎ 2. The Mathematical Package Formula

When evaluating a transaction $T$, a minerโ€™s mempool scoring engine calculates its Ancestor Feerate (also referred to as its mining score):

$$F_{\text{package}}(T) = \frac{\text{Fee}(T) + \sum_{A \in \text{Ancestors}(T)} \text{Fee}(A)}{\text{Size}(T) + \sum_{A \in \text{Ancestors}(T)} \text{Size}(A)}$$

Where: * $\text{Ancestors}(T)$ is the set of all unconfirmed parent transactions of $T$ that are currently in the mempool. * $\text{Size}$ is measured in virtual bytes (vB). * $\text{Fee}$ is denominated in satoshis (Sats).


๐Ÿ“ 3. Step-by-Step Mathematical Example

Let's walk through a live scenario where a user has received a payment that is stuck in the mempool:

The Stuck Parent ($T_P$):

The Bumping Child ($T_C$):

The recipient spends the unconfirmed output from $T_P$ to construct a child transaction $T_C$ back to themselves: * Size: $200\text{ vB}$ * Fee: $10,000\text{ Sats}$ (Individual Feerate: $50\text{ sat/vB}$)

Miner Package Evaluation:

A miner scans the mempool and computes the package feerate for $T_C$:

$$\begin{aligned} F_{\text{package}}(T_C) &= \frac{\text{Fee}(T_C) + \text{Fee}(T_P)}{\text{Size}(T_C) + \text{Size}(T_P)} \ F_{\text{package}}(T_C) &= \frac{10,000 + 250}{200 + 250} \ F_{\text{package}}(T_C) &= \frac{10,250\text{ Sats}}{450\text{ vB}} \approx \mathbf{22.78\text{ sat/vB}} \end{aligned}$$

The Outcome:

Because the collective package score of $22.78\text{ sat/vB}$ exceeds the current market clearance rate of $20\text{ sat/vB}$, the miner's block selection algorithm includes both $T_P$ and $T_C$ in their next candidate block.


โšก 4. Package Relay and BIP 331 (Mempool Constraints)

Historically, CPFP suffered from a critical bootstrap problem on the P2P network layer:

                            THE BOOTSTRAPPING BOTTLENECK

                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ”‚    Child Transaction (50 sat/vB)     โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                         โ”‚ (Rejected!)
                                         โ–ผ
                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                      โ”‚    Parent Transaction (0.5 sat/vB)   โ”‚
                      โ”‚  * Below local minrelaytxfee (1 sat) โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ˜• Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!