|
1 |
| -<!-- |
2 |
| - 300 to 1000 words |
3 |
| - put title in main newsletter |
4 |
| - put links in this file |
5 |
| - for any subheads use h3 (i.e., ###) |
6 |
| - illustrations welcome (max width 800px) |
7 |
| - if uncertain about anything, just do what seems best and harding will edit |
8 |
| ---> |
9 |
| - |
10 |
| -FIXME:glozow |
| 1 | +[Last week’s post][policy01] discussed mempool as a cache of unconfirmed |
| 2 | +transactions that provides a decentralized method for users to send |
| 3 | +transactions to miners. However, miners are not obligated to confirm |
| 4 | +those transactions; a block with just a coinbase transaction is valid |
| 5 | +by consensus rules. Users can incentivize miners to include their |
| 6 | +transactions by increasing total input value without changing total |
| 7 | +output value, allowing miners to claim the difference as transaction |
| 8 | +_fees_. |
| 9 | + |
| 10 | +Although transaction fees are common in traditional financial systems, |
| 11 | +new Bitcoin users are often surprised to find that on-chain fees are |
| 12 | +paid not in proportion to the transaction amount but by the weight of |
| 13 | +the transaction. Block space, instead of liquidity, is the limiting |
| 14 | +factor. _Feerate_ is typically denominated in satoshis per virtual |
| 15 | +byte. |
| 16 | + |
| 17 | +Consensus rules limit the space used by transactions in each block. |
| 18 | +This limit keeps block propagation times low relative to the block |
| 19 | +interval, reducing the risk of stale blocks. It also helps restrict |
| 20 | +the growth of the block chain and UTXO set, both of which directly |
| 21 | +contribute to the cost of bootstrapping and maintaining a full node. |
| 22 | + |
| 23 | +As such, as part of their role as a cache of unconfirmed transactions, |
| 24 | +mempools also facilitate a public auction for inelastic block space: |
| 25 | +when functioning properly, the auction operates on free-market |
| 26 | +principles, i.e., priority is based purely on fees rather than |
| 27 | +relationships with miners. |
| 28 | + |
| 29 | +Maximizing fees when selecting transactions for a block (which has |
| 30 | +limits on total weight and signature operations) is an [NP-hard problem][]. This problem |
| 31 | +is further complicated by transaction relationships: mining a |
| 32 | +high-feerate transaction may require mining its low-feerate parent. |
| 33 | +Put another way, mining a low-feerate transaction may open up the |
| 34 | +opportunity to mine its high-feerate child. |
| 35 | + |
| 36 | +The Bitcoin Core mempool computes the feerate for each entry and its |
| 37 | +ancestors (called _ancestor feerate_), caches that result, and uses |
| 38 | +a greedy block template building algorithm. It sorts the mempool in |
| 39 | +_ancestor score_ order (the minimum of ancestor feerate and individual |
| 40 | +feerate) and selects ancestor packages in that order, updating |
| 41 | +the remaining transactions' ancestor fee and weight information as it goes. |
| 42 | +This algorithm offers a balance between performance and profitability, |
| 43 | +and does not necessarily produce optimal results. Its efficacy can be |
| 44 | +boosted by restricting the size of transactions and ancestor |
| 45 | +packages---Bitcoin Core sets those limits to 400,000 and 404,000 weight |
| 46 | +units, respectively. |
| 47 | + |
| 48 | +Similarly, a _descendant score_ is calculated that is used when |
| 49 | +selecting packages to evict from the mempool, as it would be |
| 50 | +disadvantageous to evict a low-feerate transaction that has a |
| 51 | +high-feerate child. |
| 52 | + |
| 53 | +Mempool validation also uses fees and feerate when dealing with |
| 54 | +transactions that spend the same input(s), i.e. double-spends or |
| 55 | +conflicting transactions. Instead of always keeping the first |
| 56 | +transaction it sees, nodes use a set of rules to determine which |
| 57 | +transaction is the more incentive compatible to keep. This behavior is |
| 58 | +known as [Replace by Fee][topic rbf]. |
| 59 | + |
| 60 | +It is intuitive that miners would maximize fees, but why should a |
| 61 | +non-mining node operator implement these policies? As mentioned in |
| 62 | +last week's post, the utility of a non-mining node's mempool is |
| 63 | +directly related to its similarity to miners' mempools. As such, even |
| 64 | +if a node operator never intends to produce a block using the contents |
| 65 | +of its mempool, they have an interest in keeping the most |
| 66 | +incentive-compatible transactions. |
| 67 | + |
| 68 | +While there are no consensus rules requiring transactions to pay fees, |
| 69 | +fees and feerate play an important role in the Bitcoin network as a |
| 70 | +"fair" way to resolve competition for block space. Miners use feerate |
| 71 | +to assess acceptance, eviction, and conflicts, while non-mining nodes |
| 72 | +mirror those behaviors in order to maximize the utility of their |
| 73 | +mempools. |
| 74 | + |
| 75 | +The scarcity of block space exerts a downward pressure on the size of |
| 76 | +transactions and encourages developers to be more efficient in |
| 77 | +transaction construction. Next week's post will explore practical |
| 78 | +strategies and techniques for minimizing fees in on-chain |
| 79 | +transactions. |
| 80 | + |
| 81 | +[policy01]: /en/newsletters/2023/05/17/#waiting-for-confirmation-1-why-do-we-have-a-mempool |
| 82 | +[np-hard problem]: https://en.wikipedia.org/wiki/NP-hardness |
0 commit comments