A payment stuck in the queue
A block has room for only so much weight. When more transactions wait than fit, miners pick the ones that pay most for their size.
If your payment pays too little, it waits. This lesson shows how a node measures a fee and how a payment can be replaced. It also shows how somebody can make replacing hard.
By the end of this lesson
Note
I can decide whether a node accepts a replacement transaction.
Key words
| Word | What it means | Example |
|---|---|---|
| Mempool | the transactions a node holds before they are mined | |
| Fee rate | the fee divided by the virtual size | 2.0 sat/vB |
| Replace by fee | sending a new version that spends the same input and pays more | |
| Incremental relay fee | the extra rate a replacement must add | |
| Pinning | making a transaction costly to replace |
The cells students fill in are left blank in this preview.
Miners compare fee rates
A miner fills a block by weight, so a transaction is judged by its fee per virtual byte, not its total fee. Weight divided by 4, rounded up, is the virtual size.
When the lab started it left one payment from Bob in the mempool. It pays 220 sats for 110 virtual bytes, which is 2 sat/vB.
Look at the waiting payment and two replacements
docker exec bitcoind sh steps/fees.shShown here, not run. Press Start lab to type it into your own lab’s terminal.
Worked example: what the node said
| Transaction | Fee | vsize | The node |
|---|---|---|---|
| The waiting payment | 220 sats | 110 | in the mempool |
| Replacement, same fee | 220 sats | 110 | insufficient fee |
| Replacement, twice the fee | 440 sats | 110 | allowed |
The cells students fill in are left blank in this preview.
Try it: which pays more per byte?
# Two transactions waiting for the next block. Which would a miner pick first?
waiting = [
{"name": "big", "fee": 3000, "vsize": 1500},
{"name": "small", "fee": 900, "vsize": 150},
]
for tx in waiting:
rate = tx["fee"] / tx["vsize"]
print(tx["name"], "pays", tx["fee"], "sats, which is", rate, "sat/vB")
# Change the big one's fee to 12000. Which is first now?
A replacement must pay for itself
A node takes a replacement only if it pays more than what it pushes out. Its fee must cover the old fee plus the incremental relay fee for its own size. This node's incremental fee is 100 sats per 1000 virtual bytes, which is 0.1 sat/vB.
So replacing 220 sats on 110 virtual bytes needs at least 220 plus 11, which is 231 sats.
Work the same numbers in Python
docker exec jupyter python3 steps/feerate.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.
A common mistake
Warning
Many people think the transaction with the biggest total fee is mined first. A miner has limited weight to fill. A small transaction paying a high rate beats a large one paying more in total.
Pinning makes replacing expensive
Anybody who can spend an output of a waiting transaction can hang a child on it. A large, cheap child means a replacement must pay for pushing out both.
That matters for channels, where a closing transaction may need to be replaced in time. Newer relay rules, such as small TRUC transactions, limit children to make pinning harder.
See what a large child costs
docker exec jupyter python3 steps/pinning.pyShown here, not run. Press Start lab to type it into your own lab’s terminal.