If you’ve been following the crypto universe for a while, you’ve probably heard the term “Mempool,” especially when Bitcoin transactions seem to be stuck.
In this post, I’ll break down exactly what the Mempool is and how it plays a crucial role in the Bitcoin blockchain.
The Bitcoin Mempool, short for “Memory Pool,” is essentially a waiting room for new Bitcoin transactions before they are confirmed and added to the blockchain.
In technical terms, the Mempool is the temporary storage where all in-progress transactions are held.
Once transactions enter the Mempool, miners select them for verification and addition to the blockchain.
When any transactions occur in the Bitcoin network that can’t be added to the Bitcoin blockchain automatically. the transaction has to pass certain steps and criteria for it to become a valid transaction.
Firstly a transaction goes to a full node (full node is a node that has a complete copy of Bitcoin blockchain), and nodes have to check if the transaction is valid or not by checking the transaction following certain criteria mentioned below.
1. Check syntactic correctness.
2. Make sure neither in or out lists are empty.3. Size in bytes < MAX_BLOCK_SIZE.4. Each output value, as well as the total, must be in legal money range.5. Make sure none of the inputs have hash=0, n=-1 (coinbase transactions).6. Check that nLockTime <= INT_MAX, size in bytes >= 100, and sig opcount <= 2.7. Reject “nonstandard” transactions: scriptSig doing anything other than pushing numbers on the stack, or scriptPubkey not matching the two usual forms.8. Reject if we already have matching tx in the pool, or in a block in the main branch.9. For each input, if the referenced output exists in any other tx in the pool, reject this transaction.10. For each input, look in the main branch and the transaction pool to find the referenced output transaction. If the output transaction is missing for any input, this will be an orphan transaction. Add to the orphan transactions, if a matching transaction is not in there already.11. For each input, if the referenced output transaction is coinbase (i.e. only 1 input, with hash=0, n=-1), it must have at least COINBASE_MATURITY (100) confirmations; else reject this transaction.12. For each input, if the referenced output does not exist (e.g. never existed or has already been spent), reject this transaction.13. Using the referenced output transactions to get input values, check that each input value, as well as the sum, are in legal money range.14. Reject if the sum of input values < sum of output values.15. Reject if transaction fee (defined as sum of input values minus sum of output values) would be too low to get into an empty block.16. Verify the scriptPubKey accepts for each input; reject if any are bad.17. Add to transaction pool.18. “Add to wallet if mine”.19. Relay transaction to peers.20. For each orphan transaction that uses this one as one of its inputs, run all these steps (including this one) recursively on that orphan.
When these criteria full-filled, nodes store the transaction for passing it to miners who find correct nonce value using hardware for adding it to Bitcoin blockchain, by doing so miners receive the reward.
Simple process, right… But where is the mempool…?
Now shedding light on the important point ‘Mempool’.
During the validation process, if a transaction is valid but cannot yet be added to the blockchain, it’s placed in the Mempool.
The Bitcoin blockchain processes transactions continuously, but the network’s infrastructure isn’t always sufficient to handle the volume of transactions in real time.
The Mempool acts as a holding area within each node for these pending transactions.
Full nodes have a different RAM capacity to store unconfirmed transactions, some nodes rapidly fill up, or some nodes still have space to process transactions.
To address this imbalance, Bitcoin Core version 0.12.0 introducing ‘Mempool’.
Before this version, if a node mempool maxed out its RAM, the node would just crash and restart with an empty Mempool.
If a node’s Mempool approaches its RAM capacity, the node automatically sets a minimum fee threshold. Transactions with fees lower than this threshold are removed from the Mempool, allowing space for new transactions with higher fees.
The Mempool size fluctuates because whenever a node receives a newly mined block, it clears all Mempool transactions that have been confirmed, along with those that have conflicting inputs.
As a result of this cleaning process, you see the sharp dips and drops in the mempool size.
The concept of the Mempool is part of Bitcoin Improvement Proposal 35 (BIP 35).
Its main purpose is to allow outside nodes to access other nodes’ Mempools, which serves several important functions:
- SPV clients(also known as lite wallets) wishing to obtain zero-confirmation transactions sent or received.
- Avoiding Miners opportunity to miss lucrative fee transactions or download the current “transaction waiting list” in order to start confirming transactions.
- Remote network diagnostics to several attacks like DDoS.
Until now, you know how mempool helps Blockchain to process the transactions, but on the contrary, there are some problems with the mempool’s existence to the whole network.
Here I’m sharing some of those problems.
Inconsistent Data
Getting accurate datas about the Mempool is difficult because there are thousands of nodes holding different sizes of mempools, so the raw data is sparse and sometimes inconsistent. This makes definitive mempool data difficult to capture.
Lack of Central Authority
In the decentralized Blockchain structure, nobody says what is happening inside the mempool. Typically when a node receives the transaction and broadcasts it out for confirmation if the transaction gets stuck or lost, no central authority can tell what’s going on or help to resolve the situation.
Transaction Replacement
Mempool transactions can be overwritten with a replacement transaction; this is not like an on-chain transaction that is immutable.
The Mempool has both advantages and drawbacks for the Bitcoin blockchain.
However, its existence is largely beneficial. Thanks to the Mempool, we have tools like transaction accelerators that help boost unconfirmed transactions, and we can estimate the size of pending transactions on the network.
The Mempool also plays a role in preventing certain types of attacks on the network.
So, what’s your takeaway from the concept of the Mempool?