Mastering the Mempool: Your Intro to In-Flight Transactions
The mempool is the gateway to the blockchain. Before anything can be written on a block, it must first move through the mempool. And this important piece of Web3 is often overlooked.
Since the mempool dictates how every transaction gets written to and confirmed on-chain, understanding the mempool can help you understand what is happening with your in-flight transactions and unlock deep insights into how blockchains work.
In the course of building infrastructure to monitor the mempool, we've learned a lot about how it works. We want to share our insights about this fascinating part of the Ethereum ecosystem. To start, let’s introduce what the mempool is and why it matters to you and your Dapp.
What Is The Mempool?
A blockchain creates a permanent ledger of transactions. Once you write it, you can't unwrite it. So blockchains need a mechanism to figure out the sequence of how transactions are written to the block. The mempool is the dynamic staging area in front of the blockchain that enables transaction ordering, transaction fee prioritization, and general block construction.
The term itself —mempool— comes from Bitcoin. But in this post, we will focus on the Ethereum ecosystem. The mempool refers to the set of in-memory data structures inside an Ethereum node that stores candidate transactions before they are mined. Geth calls it the “transaction pool”; Parity calls it the “transaction queue.” Regardless of the name, it is a pool of transactions sitting in memory waiting to be included in a block. Think of it as a “waiting area” for transactions to be accepted into a block.
Valid transactions sent to an Ethereum node should enter the mempool. But there's not actually a single mempool. Rather, each node has its own mempool that attempts to remain synchronized with other nodes (peers) over the Ethereum network. Since network communication is not always reliable or timely, each node has a slightly (or sometimes significantly) different mempool. Also, nodes have different rules about which transactions they accept (e.g. minimum gas price and mempool size limits).
Ideally transactions leave a node's mempool because they are included in a block. But they can also leave because they are replaced via a speedup/cancel, or dropped due to the node's mempool configuration. We'll dive into some of the details of entering and leaving the mempool in future posts.
Mempools as a Blockchain Primitive
The concept of a mempool is fundamental to the blockchain itself. And the history of the mempool is the history of the blockchain.
It is a core component of how blockchains move transactions from a user’s Wallet to confirmation in a block.
But in spite of its importance, the mempool is not mentioned in any major chain’s whitepaper. It isn’t even mentioned on Wikipedia.
Do you remember what we said at the beginning of this post? The mempool is often overlooked. Now that we’ve filled you in on the background of the mempool, let’s explore in a little more detail how it is part of a typical transaction flow.
How Does The Mempool Fit In a Typical Transaction Flow?
A typical transaction flow includes the following steps:
- First, a user initiates a transaction from a Dapp or Wallet, such as sending funds to another account or contract
- Then the user signs that transaction with their Wallet
- The Wallet sends the signed transaction to a node, often called a gateway node, to get onto the Ethereum network (think Infura or Pocket)
- That node will verify the transaction is valid and add it to its mempool
- Since the node is connected to a group of peers, it broadcasts the transaction to other nodes.
- These peer nodes will receive the transaction, validate it, move it into their own mempool, and broadcast to additional peers, essentially replicating the transaction across the network
- Miners, as a specific kind of node, also receive the transaction from peers, validate it, and attempt to add it to a block
- Eventually, a successful miner adds a block with the transaction to the chain
- The new block is broadcast over the network
- As all nodes receive the new block from their peers, they see the included transaction and remove it from their mempool
That's quite a few steps. And remember, this is the process when everything goes right! In the event that things go sideways — as they inevitably do — the transaction flow can get more complex.
Before any transaction can become part of the blockchain, it must move through the mempool. And this piece of Web3 infrastructure is overlooked and often misunderstood. Think of the mempool as a waiting area for your transaction. Nodes see incoming transactions, ensure they meet basic requirements, and then broadcast them to peer groups. Eventually, miners will grab pending transactions from nodes and include them in a block — earning a fee for their service. It’s only when a transaction is finalized in a block that it will leave the mempool for good.
Blocknative will explore each aspect of the Ethereum mempool in-depth in future posts. We will look at the structure of the mempool, how each node keeps its mempool in sync with peers, how different transaction situations are handled in the mempool, and other mempool details. To learn more and join the conversation, follow us @Blocknative.