Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part IV · Surviving the long run This chapter answers the questions real users actually ask.

Every chapter so far has been “how the system works.” This one switches viewpoint: where exactly is your transaction between the moment you send it and the moment it lands in a block?

Four questions:

  • Why hasn’t my transaction confirmed?

  • Why isn’t it first-come, first-served?

  • I underpaid — can I fix it?

  • Why can one confirmation still disappear?


12.1 The mempool: a waiting basket

After broadcast a transaction does not go straight into a block. It waits in the mempool of many nodes.

Here is a fact most people don’t know:

There is no single global mempool. Every node has its own, usually similar, never guaranteed identical.

Chapter 7’s sentence lands here: the mempool is “I heard about this”; the blockchain is “the network finally accepted this.”

txA fee= 1000 size= 500 feerate= 2.0
txB fee= 700 size= 200 feerate= 3.5
txC fee= 900 size= 150 feerate= 6.0
txD fee= 450 size= 300 feerate= 1.5
txE fee= 300 size= 250 feerate= 1.2

mempool is a list of dictionaries. No other structure.

Now look at feerate — this is the chapter’s first counterintuitive point.

Miners do not care about the total fee. They care about the rate: how much they earn per unit of block space.

Compare txA and txC in the output:

txA  fee=1000  size=500  feerate=2.0
txC  fee=900   size=150  feerate=6.0

txA pays more in total (1000 > 900), and txC gets in first.

Because txA occupies more than three times the room. A miner is not selling a service. He is selling block space. What you pay is not “the price of a transaction” — it is rent per byte.

(Which is why your wallet quotes sat/vB — satoshis per byte — rather than a total.)


12.2 How a miner packs a block

packed into the block: ['txC', 'txB', 'txD']
total size: 650  total fees: 2050
left out: ['txA', 'txE']

Notice the if used + tx["size"] <= max_size: — anything that doesn’t fit is skipped and the loop continues rather than stopping.

Which means a transaction with a mediocre fee rate but a small size can get in simply by fitting into the gap left over.

(This is really a knapsack problem, and pick_block is a greedy approximation. Real Bitcoin is greedy too — the optimal solution is NP-hard and a miner has seconds. This is the first place in the book where we settle for good-enough because optimal is unavailable: the line between engineering and mathematics.)

block space  400 -> ['txC', 'txB']
block space  650 -> ['txC', 'txB', 'txD']
block space 1000 -> ['txC', 'txB', 'txA']
block space 1400 -> ['txC', 'txB', 'txA', 'txD', 'txE']

Those four lines are the whole fee market:

More people want in than there is room.
Miners take the highest rate first.
Anyone who wants speed raises their rate.

No authority sets the price. Competition for finite block space produces it.


12.3 Speeding up, method one: RBF

Your fee rate was too low and the transaction is stuck. Now what?

RBF = Replace-By-Fee:

I sent a low-fee transaction.
It hasn't confirmed.
I send a new transaction spending the same coin, with a higher fee.
Nodes may replace the old one with the new one.

Note this does not add money to the old transaction. It broadcasts a more expensive replacement that pushes the original out.

before: ['txA', 'txB', 'txC', 'txD', 'txE', 'pay_low']
replaced pay_low
after : ['txA', 'txB', 'txC', 'txD', 'txE', 'pay_high']

Look at what conflicts checks: whether two transactions spend the same input.

Go back to chapter 6 — two transactions spending the same input is a double-spend.

So what RBF does, literally, is deliberately initiate a double-spend, where one version pays more and the nodes are willing to swap.

RBF is not a double-spend loophole. RBF is double-spending, in the one form the rules have chosen to accept.

This is exactly why a merchant cannot safely accept a zero-confirmation payment: an unconfirmed transaction can be replaced by its sender at any moment.


12.4 Speeding up, method two: CPFP

Only the sender can use RBF — it requires spending the same input, which requires the key.

So can a recipient who sees an underpaying transaction do anything? Yes.

CPFP = Child-Pays-For-Parent:

The parent's fee is too low; miners aren't interested.
But a child transaction spends the parent's output and pays a very high fee.
The child cannot confirm before the parent does.
So a miner who wants the child's fee has to include both.
parent alone, fee rate: 0.2
child alone, fee rate : 9.17 -- but it depends on the parent
parent+child package  : 1.94
miner's minimum fee rate: 1.5
is the parent enough on its own? False
are they enough together?       True

The key is package_feerate: it treats parent and child as a single unit.

The parent alone rates 0.2 and misses the threshold. Together they rate 1.94 and clear it. A miner who wants the child’s 1100 has no choice but to carry the parent along.

In one line:

RBF : replace the old transaction with a more expensive one.   (sender only)
CPFP: use a high-fee child to drag a low-fee parent into a block.  (anyone)

12.5 What a miner picks determines the block’s fingerprint

Now chapters 5, 10 and 11 come together.

originally packed: ['txC', 'txB', 'txD']
Merkle root: b816616688b7bc9774  block hash: af27b53088d67a249c

packed after RBF : ['txC', 'pay_high', 'txB']
Merkle root: 6a6e48bc642766d9e2  block hash: 4795431218b0877474
same root? False

This is the first place several threads in the book fully converge:

Fees decide which transactions a miner picks       (chapter 10)
      |
The transaction set determines the Merkle root     (chapter 11)
      |
The Merkle root goes into the block header         (chapter 11)
      |
The block header must be re-mined                  (chapter 5)

So every time a miner swaps a transaction, mining restarts from scratch. Which explains something practical: miners generally do not churn their transaction set mid-block — every change throws away the work done so far.


12.6 Reorgs: why one confirmation can vanish

Chapter 7’s rule says nodes follow the valid chain with the most accumulated work.

If your transaction went into a block on one chain, and another chain later becomes heavier, nodes switch. That switch is a chain reorganization, or reorg.

chain seen first : ['A', 'B', 'C'] work = 3
chain that wins  : ['A', 'B', 'C_other', 'D_other'] work = 4
nodes now follow : ['A', 'B', 'C_other', 'D_other']
dropped back to the mempool: ['pay_to_shop']

pay_to_shop is gone.

It had one confirmation. The merchant may already have shipped. Then another chain won and that transaction was thrown back into the mempool — as if it had never happened.

Note that nobody cheated here. Both chains are valid; network latency simply had different miners working on different branches, and the heavier one won. A reorg is not an attack. It is part of the design.

What a confirmation actually is

0 confirmations: in the mempool, not in a block
1 confirmation : in a block, but shallow
2 confirmations: another block on top
6 confirmations: buried deeper -- reorging it out requires far more work

A confirmation is a measure of how deeply a transaction is buried in history.

And an attacker is not “editing one transaction.” He is racing every miner on Earth.

One confirmation means the attacker is one block behind. Six means six. If he is slower than the honest network, the further behind he falls, the lower his chance of ever catching up.

The whitepaper’s final section computes exactly this: given z blocks behind, what is the probability the attacker catches up?

The answer decays exponentially in z. So “six confirmations” is not a magic number. It is simply a depth at which the probability has become small enough to accept.

And where that depth should be depends on the amount. Chapter 8’s opportunity cost returns here: one confirmation is fine for a coffee; six may not be enough for a house.

(Remember section 5.2? Block intervals have enormous variance. So “six confirmations” does not mean “one hour” — it might be twenty minutes or it might be two. That geometric distribution again.)

YOUR TURN


12.7 The ledger

What you wroteField
mempool — each node’s own waiting basketNetworking + node policy
feerate — rent per byteEconomics
pick_block() — greedy packingEconomics + algorithms (approximate knapsack)
add_with_rbf() — the double-spend the rules acceptNode policy
package_feerate() — CPFPMiner economics
merkle_root() — transaction set to block fingerprintCryptography (chapter 11’s)
Chain reorganizationConsensus

This is the book’s most cross-cutting chapter: user experience, miner economics, node policy, Merkle structure and longest-chain consensus all meet here.

It is also the chapter closest to the lived experience of using Bitcoin. Every “speed up transaction” button, every estimated confirmation time, every “why hasn’t this arrived yet” traces back to this material.


Next

Switching to the real curve, secp256k1.

The close of Part IV, and something of a ceremony.

You will replace the toy curve from chapters 2 and 3 — mod 23, twenty-nine points — with the one Bitcoin actually uses, and find that almost nothing in your code has to change.

Exactly one thing must. And that one thing is chapter 2’s complexity intuition, finally put to work.