-
Notifications
You must be signed in to change notification settings - Fork 107
refactor(l1): enhance mempool oldest removal #4638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This reverts commit 33da12b.
There was a problem hiding this 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 oneRwLock
- Replaces the
Vec<H256>
order tracking with aVecDeque<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.
Lines of code reportTotal lines added: Detailed view
|
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