How Ethereum Transactions Are Purged from the Transaction Pool in the Client Codebase
As we delve into the intricacies of the Ethereum client codebase, specifically Geth, cpp-Ethereum, and OpenEthereum, it is essential to understand how transactions are processed within the blockchain. One critical aspect of the client is transaction pool handling, where incoming transactions are added to blocks for verification and validation.
In this article, we will focus on the process of purging transactions from the transaction pool in the client codebase, highlighting specific functions and their roles.
Client Codebase Overview
Ethereum client codebases provide a comprehensive implementation of the Ethereum Virtual Machine (EVM) architecture. They are responsible for:
- Transaction Management: Handling incoming transactions, including verification and validation.
- Block Management: Creating new blocks, updating existing ones, and removing them from the blockchain.
Purge Transactions from the Transaction Pool
Let’s dive into how transactions are processed in the client codebase.

commitWork
commitWork is a function within the eth_blockstore module that commits work to a block. Three arguments are required:
data: Data for the new block, including transaction IDs and values.
index: the index of the first unspent entry (UI) in the transaction.
gas_price: Gas price used during transaction verification.
The function clears transactions from the pool by removing them if they don’t have enough funds to cover the cost. Specifically, it calls two functions:
fillTransactions(): This function is responsible for filling the transaction pool with new transactions that can be added to blocks.
checkFees()andfillFee():These functions are used to check transaction fees and fill any remaining balance with gas.
fillTransactions()
fillTransactions() is a critical function in clearing transactions from the pool. Three arguments are required:
txs: List of transactions to be added to the block.
balance: Current balance in the Ethereum account.
gasPrice: Gas price used during transaction verification.
The function iterates over each transaction, calculating its cost and available funds. If a transaction does not have enough funds or does not have enough user interfaces to cover the cost, it is removed from the set.
checkFees()
checkFees() is called after fillTransactions() to calculate the total transaction fees. It returns an array of fee ranges, allowing the client to decide which transactions to add to the block based on available balance and fees.
fillFee():
fillFee() calculates the remaining balance in the Ethereum account after adding new transactions to the set. It is used to determine whether or not additional transactions can be added.
In the client codebase
In Geth, cpp-Ethereum, and OpenEthereum, these functions are implemented as follows:
Geth: In theeth_blockstoremodule (src/main.rs),commitWork()is called directly from thefillTransactions()function.
cpp-Ethereum: in the filesrc/main.cppa similar implementation is available for cleaning up transactions.
OpenEthereum: The OpenEthereum codebase provides an even more detailed explanation of these functions in its source code (src/main.rs) and implementation (src/eth_blockstore.rs).
In summary, client codebases perform different steps to purge transactions from the pool:
commitWork()checks for valid transactions that can be added to blocks.
fillTransactions(): Repeats each transaction, calculating its costs and available funds.
checkFees()calculates the total transaction fees and determines which ones should be added to the blocks.
4.