Skip to content

Conversation

gianbelinche
Copy link
Contributor

Motivation
The removal of elements from the mempool when it is full is not efficient.

Description
Now the array that represent the order of insertion to the mempool is a vecdeque, which is not changed when an arbitrary element is removed from the mempool.
Only when the mempool is full, we remove from the vecdeque until we find an element present in the mempool.
Also if the vecdeque is greater than 150% of the maximum mempool size, we prune it, keeping only the txs that are actually in the mempool, preserving the order.

Closes #4605

@gianbelinche gianbelinche requested a review from a team as a code owner September 24, 2025 18:19
@Copilot Copilot AI review requested due to automatic review settings September 24, 2025 18:19
@gianbelinche gianbelinche changed the base branch from main to refactor-mempool-locks September 24, 2025 18:19
@github-actions github-actions bot added the L1 Ethereum client label Sep 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the mempool to improve efficiency of oldest transaction removal when the pool is full. The main changes involve restructuring the mempool's internal data structures and optimizing the removal process.

  • Consolidates all mempool data structures into a single MempoolInner struct protected by one RwLock
  • Replaces the Vec<H256> order tracking with a VecDeque<H256> that is lazily cleaned
  • Implements a pruning mechanism that removes stale entries from the order queue when it exceeds 150% of max capacity

Reviewed Changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

File Description
crates/blockchain/mempool.rs Major refactoring of mempool structure and oldest transaction removal logic
crates/networking/p2p/tx_broadcaster.rs Updates method call to handle new return type

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

github-actions bot commented Sep 24, 2025

Lines of code report

Total lines added: 13
Total lines removed: 0
Total lines changed: 13

Detailed view
+-------------------------------------+-------+------+
| File                                | Lines | Diff |
+-------------------------------------+-------+------+
| ethrex/crates/blockchain/mempool.rs | 727   | +13  |
+-------------------------------------+-------+------+

@github-project-automation github-project-automation bot moved this to In Review in ethrex_l1 Sep 25, 2025
Base automatically changed from refactor-mempool-locks to main September 26, 2025 16:06
@gianbelinche gianbelinche added this pull request to the merge queue Sep 26, 2025
Merged via the queue into main with commit ff49e35 Sep 26, 2025
36 checks passed
@gianbelinche gianbelinche deleted the mempool-better-queue branch September 26, 2025 20:43
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L1 Ethereum client
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Refactor removing transaction in mempool
3 participants