Block Packing

Choosing and ordering transactions to maximise the value a block extracts under its size and weight limits.

Basically

Block packing means choosing which transactions go into a new block and in which order. You can use it to collect the most fees or pursue other goals.

Key Takeaways

  • Block packing is how miners and validators choose which mempool transactions to include in a new block. They aim for the highest total fee revenue within the block's capacity limit.
  • Block packing resembles a knapsack problem because transactions vary in size and fee. The goal is to maximise total fees without exceeding the block weight limit. The general problem is NP-hard, but greedy feerate sorting produces near-optimal results in practice.
  • Bitcoin and Ethereum approach block packing differently. Bitcoin Core uses feerate-based sorting with dependency awareness, while Ethereum uses specialised block builders that compete in auctions to extract MEV alongside transaction fees.

What Is Block Packing?

Block packing selects and orders transactions from a node's mempool to construct a new block. Every block has finite capacity: Bitcoin enforces a limit of 4,000,000 weight units, equivalent to 1,000,000 virtual bytes, while Ethereum caps blocks at 30 million gas. The mempool usually holds more transactions than fit in one block, so the block producer must choose which transactions to include and in what order.

The simplest objective is to maximise total transaction fees. Miners and validators earn fees from every included transaction, so packing the most fee-dense transactions yields the highest revenue. Dependencies between transactions, such as a child spending from an unconfirmed parent, and Ethereum's opportunities to extract value through transaction ordering add significant complexity.

The result of block packing is a block template. A block template is an ordered list of transactions ready for the block producer to mine or propose.

The Knapsack Problem

Block packing maps directly to the classic knapsack problem from computer science. Each transaction has a "weight", its size in vbytes or weight units, and a "value", the fee it pays, while the block's capacity sets the knapsack's weight limit. The goal is to maximise total value without exceeding capacity.

The general knapsack problem is NP-hard, so no known algorithm solves it optimally in polynomial time, but block packing is far more tractable in practice. Typical transactions average around 250 to 500 vbytes, so a block capacity of 1,000,000 vbytes can hold thousands of transactions. When many small, similarly sized items compete for space, a greedy algorithm that sorts by fee density and picks from the top produces results very close to optimal.

Transaction dependencies create complications. The UTXO model does not allow a child transaction to be included without its unconfirmed parent. The block assembler therefore cannot sort all transactions independently and must consider packages of related transactions together.

Bitcoin Core's Block Assembly Algorithm

Bitcoin Core builds block templates with an algorithm based on ancestor feerate sorting. Introduced in 2016, this approach treats each transaction as part of a package that includes all its unconfirmed ancestors, not in isolation.

Bitcoin Core follows a greedy process. The algorithm selects transaction packages by ancestor feerate while accounting for unconfirmed ancestors.

The greedy algorithm handles the dependency problem elegantly. A low-fee parent with a high-fee child enters the block because the child's ancestor feerate accounts for the parent's weight. The approach is conceptually similar to child-pays-for-parent (CPFP): a generous child fee effectively subsidises its parent's inclusion.

Cluster Mempool and Chunk Feerate

The ancestor feerate algorithm has a known limitation: complex transaction graphs can lead to suboptimal block templates in certain edge cases. Cluster mempool, a major redesign of Bitcoin Core's mempool infrastructure, addresses this limitation with a more rigorous approach based on linearisation and chunk feerates.

Cluster mempool groups related transactions into clusters. Each cluster is linearised into an optimal ordering and split into "chunks", which are contiguous groups of transactions that should be included together. Block building then means taking chunks in descending feerate order across all clusters until the block is full.

Pieter Wuille's analysis shows that near-optimal linearisations bound the total fee loss from this chunk-based approach by the unfilled block space multiplied by the feerate of the first chunk that does not fit. In practice, the approach produces block templates closer to optimal than the legacy ancestor feerate algorithm.

Ethereum Block Building

Ethereum's approach to block packing differs fundamentally from Bitcoin's. Proposer-builder separation (PBS) separates the roles of constructing and proposing blocks. Specialised block builders compete in an auction run through MEV-Boost relays, bidding for the right to have their block included by the proposing validator.

Ethereum builders optimise for more than transaction fees. They also extract maximal extractable value (MEV) through strategies such as arbitrage, liquidations and sandwich attacks. A builder's block packing algorithm considers both which transactions to include and their precise ordering, because the sequence of state changes determines MEV opportunities.

The result is significant builder concentration. As of 2024, MEV-Boost handled approximately 90% of Ethereum blocks, with just a handful of builders producing the vast majority. Efforts like enshrined PBS (ePBS) aim to bring builder separation into the consensus layer, reduce reliance on trusted relays and improve decentralisation.

Mining Revenue Optimisation

The primary use case for block packing is maximising miner or validator revenue. During periods of high network congestion, the difference between a well-packed and poorly packed block can be substantial. Optimal packing ensures that the highest-value transactions are included first, directly affecting the block producer's block reward from fees.

Fee Market Dynamics

Block packing algorithms define the fee market by determining the minimum feerate required for inclusion. When blocks are full, the packing algorithm's selection threshold becomes the effective floor price for block space. You must bid above this threshold to get your transaction confirmed, creating a competitive market for scarce block capacity.

Transaction Prioritisation

Bitcoin Core supports the prioritisetransaction RPC, which lets node operators add a fee delta to specific transactions. The block assembly algorithm uses these modified fees during ancestor feerate calculation, so miners can prioritise specific transactions, such as their own consolidation transactions, without those transactions actually paying higher on-chain fees.

Fee Estimation

Wallet fee estimation algorithms depend on how block packing works. By simulating block assembly against the current mempool, wallets can predict the feerate needed for confirmation within a target number of blocks. Bitcoin Core's MiniMiner uses the same ancestor-set scoring algorithm for this purpose.

Centralisation Pressure

Sophisticated block packing algorithms can create centralisation pressure. In Ethereum, the complexity of MEV extraction has concentrated block production among a small number of specialised builders. In Bitcoin, the simpler fee-maximisation objective keeps block template construction accessible to individual miners, but any shift towards MEV-style optimisation on Bitcoin layer 2s could introduce similar dynamics.

Suboptimal Templates

No polynomial-time algorithm guarantees optimal block packing in all cases. The ancestor feerate heuristic can miss better arrangements when complex dependency chains create conflicting incentives. Cluster mempool improvements significantly narrow this gap, but perfect optimality remains computationally intractable for arbitrary transaction graphs.

Transaction Pinning

Transaction pinning exploits weaknesses in block packing algorithms. An attacker can craft transactions that manipulate feerate calculations to prevent a victim's transaction from entering a block template. Cluster mempool's improved linearisation makes certain pinning vectors harder to exploit, but the attack surface remains a concern for time-sensitive protocols like Lightning.

MEV and Fairness

Ethereum block packing is inseparable from MEV extraction. Builders routinely reorder, insert or censor transactions to capture value. PBS isolates validators from needing to run MEV strategies themselves, but the system raises fairness concerns because ordinary users may receive worse execution prices due to sandwich attacks and other extractive ordering strategies.

Further Reading

The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms