Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# Mempool design and limits3## Definitions5We view the unconfirmed transactions in the mempool as a directed graph,6with an edge from transaction B to transaction A if B spends an output created7by A (i.e., B is a **child** of A, and A is a **parent** of B).9A transaction's **ancestors** include, recursively, its parents, the parents of10its parents, etc. A transaction's **descendants** include, recursively, its11children, the children of its children, etc.13A **cluster** is a connected component of the graph, i.e., a set of14transactions where each transaction is reachable from any other transaction in15the set by following edges in either direction. The cluster corresponding to a16given transaction consists of that transaction, its ancestors and descendants,17and the ancestors and descendants of those transactions, and so on.19Each cluster is **linearized**, or sorted, in a topologically valid order (i.e.,20no transaction appears before any of its ancestors). Our goal is to construct a21linearization where the highest feerate subset of a cluster appears first,22followed by the next highest feerate subset of the remaining transactions, and23so on[1]. We call these subsets **chunks**, and the chunks of a linearization24have the property that they are always in monotonically decreasing feerate25order.27Given two or more linearized clusters, we can construct a linearization of the28union by simply merge sorting the chunks of each cluster by feerate.30For any set of linearized clusters, then, we can define the **feerate diagram**31of the set by plotting the cumulative fee (y-axis) against the cumulative size32(x-axis) as we progress from chunk to chunk. Given two linearizations for the33same set of transactions, we can compare their feerate diagrams by34comparing their cumulative fees at each size value. Two diagrams may be35**incomparable** if neither contains the other (i.e., there exist size values at36which each one has a greater cumulative fee than the other). Or, they may be37**equivalent** if they have identical cumulative fees at every size value; or38one may be **strictly better** than the other if they are comparable and there39exists at least one size value for which the cumulative fee is strictly higher40in one of them.42For more background and rationale, see [2] and [3] below.44## Mining/eviction46As described above, the linearization of each cluster gives us a linearization47of the entire mempool. We use this ordering for both block building and48eviction, by selecting chunks at the front of the linearization when49constructing a block template, and by evicting chunks from the back of the50linearization when we need to free up space in the mempool.52## Replace-by-fee54Prior to the cluster mempool implementation, it was possible for replacements55to be prevented even if they would make the mempool more profitable for miners,56and it was possible for replacements to be permitted even if the newly accepted57transaction was less desirable to miners than the transactions it was58replacing. With the ability to construct linearizations of the mempool, we're59now able to compare the feerate diagram of the mempool before and after a60proposed replacement, and only accept the replacement if it makes the feerate61diagram strictly better.63In simple cases, the intuition is that a replacement should have a higher64feerate and fee than the transaction(s) it replaces. But for more complex cases65(where some transactions may have unconfirmed parents), there may not be a66simple way to describe the fee that is needed to successfully replace a set of67transactions, other than to say that the overall feerate diagram of the68resulting mempool must improve somewhere and not be worse anywhere.70## Mempool limits72### Motivation74Selecting chunks in decreasing feerate order when building a block template75will be close to optimal when the maximum size of any chunk is small compared76to the block size. And for mempool eviction, we don't wish to evict too much of77the mempool at once when a single (potentially small) transaction arrives that78takes us over our mempool size limit. For both of these reasons, it's desirable79to limit the maximum size of a cluster and thereby limit the maximum size of80any chunk (as a cluster may consist entirely of one chunk).82The computation required to linearize a transaction grows (in polynomial time)83with the number of transactions in a cluster, so limiting the number of84transactions in a cluster is necessary to ensure that we're able to find good85(ideally, optimal) linearizations in a reasonable amount of time.87### Limits89Transactions submitted to the mempool must not result in clusters that would90exceed the cluster limits (64 transactions and 101 kvB total per cluster).92## References/Notes93[1] This is an instance of the maximal-ratio closure problem, which is closely94related to the maximal-weight closure problem, as found in the field of mineral95extraction for open pit mining.97[2] See98https://delvingbitcoin.org/t/an-overview-of-the-cluster-mempool-proposal/39399for a high level overview of the cluster mempool implementation (PR#33629,100since v31.0) and its design rationale.102[3] See https://delvingbitcoin.org/t/mempool-incentive-compatibility/553 for an103explanation of why and how we use feerate diagrams for mining, eviction, and104evaluating transaction replacements.
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.