Mempool optimizations#2062
Merged
Merged
Conversation
5bdfc4f to
7a1ed16
Compare
OBorce
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MempoolStorethat have tx id as the key were changed from btree-based to hash-based. Note that I decided to usehashbrown's containers directly, instead of using the standard ones (which also usehashbrownunder the hood), because the size estimation is more precise in this case.TxPool::remove_expired_transactionswould iterate the entireMempoolStore::txs_by_creation_timeeven though only the first few txs need to be checked.MempoolStorehad methodsrefresh_ancestors/refresh_descendants, which were called fromadd_to_descendant_score_index/remove_from_ancestor_score_index/remove_from_descendant_score_index- they would remove all ancestors/descendants fromtxs_by_ancestor_scoreortxs_by_descendant_scoreand reinsert them with the new score. I removed theserefresh_methods, and nowtxs_by_ancestor_score/txs_by_descendant_scoreare updated in the places where the score is modified - inupdate_ancestor_state_for_add/update_ancestor_state_for_drop/update_descendant_state_for_drop.TxMempoolEntryWithAncestorsstruct, so that the collected ancestors can be re-used at least during the new entry initialization.I also updated comments and did some renaming in
get_best_tx_ids_by_score_and_ancestryand its helper functioncollect_selected_ancestors(which is now calledcollect_nearest_selected_ancestorsand is in a separate module). The logic here wasn't changed, it's just that the old comments and naming were misleading.