11use std:: {
2- collections:: { BTreeMap , HashMap , VecDeque } ,
2+ collections:: { BTreeMap , VecDeque } ,
33 sync:: RwLock ,
44} ;
55
6+ use rustc_hash:: FxHashMap ;
7+
68use crate :: {
79 constants:: {
810 TX_ACCESS_LIST_ADDRESS_GAS , TX_ACCESS_LIST_STORAGE_KEY_GAS , TX_CREATE_GAS_COST ,
@@ -22,8 +24,8 @@ use tracing::warn;
2224#[ derive( Debug , Default ) ]
2325struct MempoolInner {
2426 broadcast_pool : HashSet < H256 > ,
25- transaction_pool : HashMap < H256 , MempoolTransaction > ,
26- blobs_bundle_pool : HashMap < H256 , BlobsBundle > ,
27+ transaction_pool : FxHashMap < H256 , MempoolTransaction > ,
28+ blobs_bundle_pool : FxHashMap < H256 , BlobsBundle > ,
2729 txs_by_sender_nonce : BTreeMap < ( H160 , u64 ) , H256 > ,
2830 txs_order : VecDeque < H256 > ,
2931 max_mempool_size : usize ,
@@ -35,7 +37,7 @@ impl MempoolInner {
3537 fn new ( max_mempool_size : usize ) -> Self {
3638 MempoolInner {
3739 txs_order : VecDeque :: with_capacity ( max_mempool_size * 2 ) ,
38- transaction_pool : HashMap :: with_capacity ( max_mempool_size) ,
40+ transaction_pool : FxHashMap :: with_capacity_and_hasher ( max_mempool_size, Default :: default ( ) ) ,
3941 max_mempool_size,
4042 mempool_prune_threshold : max_mempool_size + max_mempool_size / 2 ,
4143 ..Default :: default ( )
@@ -191,7 +193,7 @@ impl Mempool {
191193 pub fn filter_transactions (
192194 & self ,
193195 filter : & PendingTxFilter ,
194- ) -> Result < HashMap < Address , Vec < MempoolTransaction > > , StoreError > {
196+ ) -> Result < FxHashMap < Address , Vec < MempoolTransaction > > , StoreError > {
195197 let filter_tx = |tx : & Transaction | -> bool {
196198 // Filter by tx type
197199 let is_blob_tx = matches ! ( tx, Transaction :: EIP4844Transaction ( _) ) ;
@@ -229,9 +231,9 @@ impl Mempool {
229231 /// Gets all the transactions in the mempool
230232 pub fn get_all_txs_by_sender (
231233 & self ,
232- ) -> Result < HashMap < Address , Vec < MempoolTransaction > > , StoreError > {
233- let mut txs_by_sender: HashMap < Address , Vec < MempoolTransaction > > =
234- HashMap :: with_capacity ( 128 ) ;
234+ ) -> Result < FxHashMap < Address , Vec < MempoolTransaction > > , StoreError > {
235+ let mut txs_by_sender: FxHashMap < Address , Vec < MempoolTransaction > > =
236+ FxHashMap :: with_capacity_and_hasher ( 128 , Default :: default ( ) ) ;
235237 let tx_pool = & self . read ( ) ?. transaction_pool ;
236238
237239 for ( _, tx) in tx_pool. iter ( ) {
@@ -250,9 +252,9 @@ impl Mempool {
250252 pub fn filter_transactions_with_filter_fn (
251253 & self ,
252254 filter : & dyn Fn ( & Transaction ) -> bool ,
253- ) -> Result < HashMap < Address , Vec < MempoolTransaction > > , StoreError > {
254- let mut txs_by_sender: HashMap < Address , Vec < MempoolTransaction > > =
255- HashMap :: with_capacity ( 128 ) ;
255+ ) -> Result < FxHashMap < Address , Vec < MempoolTransaction > > , StoreError > {
256+ let mut txs_by_sender: FxHashMap < Address , Vec < MempoolTransaction > > =
257+ FxHashMap :: with_capacity_and_hasher ( 128 , Default :: default ( ) ) ;
256258 let tx_pool = & self . read ( ) ?. transaction_pool ;
257259
258260 for ( _, tx) in tx_pool. iter ( ) {
0 commit comments