11//! The internal transaction pool implementation.
22use crate :: {
3+ config:: MAX_ACCOUNT_SLOTS_PER_SENDER ,
34 error:: PoolError ,
45 identifier:: { SenderId , TransactionId } ,
56 pool:: {
@@ -9,7 +10,7 @@ use crate::{
910 state:: { SubPool , TxState } ,
1011 AddedPendingTransaction , AddedTransaction ,
1112 } ,
12- PoolResult , PoolTransaction , TransactionOrdering , ValidPoolTransaction , U256 ,
13+ PoolConfig , PoolResult , PoolTransaction , TransactionOrdering , ValidPoolTransaction , U256 ,
1314} ;
1415use fnv:: FnvHashMap ;
1516use reth_primitives:: TxHash ;
@@ -64,6 +65,8 @@ pub struct TxPool<T: TransactionOrdering> {
6465 sender_info : FnvHashMap < SenderId , SenderInfo > ,
6566 /// pending subpool
6667 pending_pool : PendingPool < T > ,
68+ /// Pool settings to enforce limits etc.
69+ config : PoolConfig ,
6770 /// queued subpool
6871 ///
6972 /// Holds all parked transactions that depend on external changes from the sender:
@@ -84,13 +87,14 @@ pub struct TxPool<T: TransactionOrdering> {
8487
8588impl < T : TransactionOrdering > TxPool < T > {
8689 /// Create a new graph pool instance.
87- pub fn new ( ordering : Arc < T > ) -> Self {
90+ pub fn new ( ordering : Arc < T > , config : PoolConfig ) -> Self {
8891 Self {
8992 sender_info : Default :: default ( ) ,
9093 pending_pool : PendingPool :: new ( ordering) ,
9194 queued_pool : Default :: default ( ) ,
9295 basefee_pool : Default :: default ( ) ,
93- all_transactions : Default :: default ( ) ,
96+ all_transactions : AllTransactions :: new ( config. max_account_slots ) ,
97+ config,
9498 }
9599 }
96100 /// Updates the pool based on the changed base fee.
@@ -313,6 +317,8 @@ pub struct AllTransactions<T: PoolTransaction> {
313317 minimal_protocol_basefee : U256 ,
314318 /// The max gas limit of the block
315319 block_gas_limit : u64 ,
320+ /// Max number of executable transaction slots guaranteed per account
321+ max_account_slots : usize ,
316322 /// _All_ transactions identified by their hash.
317323 by_hash : HashMap < TxHash , Arc < ValidPoolTransaction < T > > > ,
318324 /// _All_ transaction in the pool sorted by their sender and nonce pair.
@@ -322,6 +328,11 @@ pub struct AllTransactions<T: PoolTransaction> {
322328}
323329
324330impl < T : PoolTransaction > AllTransactions < T > {
331+ /// Create a new instance
332+ fn new ( max_account_slots : usize ) -> Self {
333+ Self { max_account_slots, ..Default :: default ( ) }
334+ }
335+
325336 /// Returns if the transaction for the given hash is already included in this pool
326337 pub ( crate ) fn contains ( & self , tx_hash : & TxHash ) -> bool {
327338 self . by_hash . contains_key ( tx_hash)
@@ -588,6 +599,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
588599impl < T : PoolTransaction > Default for AllTransactions < T > {
589600 fn default ( ) -> Self {
590601 Self {
602+ max_account_slots : MAX_ACCOUNT_SLOTS_PER_SENDER ,
591603 pending_basefee : Default :: default ( ) ,
592604 minimal_protocol_basefee : MIN_PROTOCOL_BASE_FEE ,
593605 block_gas_limit : 30_000_000 ,
0 commit comments