Skip to content

Commit 794c073

Browse files
authored
feat(txpool): extend poolconfig (#61)
1 parent 6b71460 commit 794c073

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
/// Guarantees max transactions for one sender, compatible with geth/erigon
2+
pub(crate) const MAX_ACCOUNT_SLOTS_PER_SENDER: usize = 16;
3+
14
///! Configuration options for the Transaction pool.
25
#[derive(Debug, Clone)]
36
pub struct PoolConfig {
4-
// TODO add limits for subpools
5-
// TODO limits for per peer
6-
// TODO config whether to check if transactions are banned
7+
/// Max number of transaction in the pending sub-pool
8+
pub pending_limit: usize,
9+
/// Max number of transaction in the basefee sub-pool
10+
pub basefee_limit: usize,
11+
/// Max number of transaction in the queued sub-pool
12+
pub queued_limit: usize,
13+
/// Max number of executable transaction slots guaranteed per account
14+
pub max_account_slots: usize,
715
}
816

917
impl Default for PoolConfig {
1018
fn default() -> Self {
11-
todo!()
19+
Self {
20+
pending_limit: 10_000,
21+
basefee_limit: 10_000,
22+
queued_limit: 10_000,
23+
max_account_slots: MAX_ACCOUNT_SLOTS_PER_SENDER,
24+
}
1225
}
1326
}

crates/transaction-pool/src/pool/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ where
114114
T: TransactionOrdering<Transaction = <V as TransactionValidator>::Transaction>,
115115
{
116116
/// Create a new transaction pool instance.
117-
pub fn new(client: Arc<V>, ordering: Arc<T>, config: PoolConfig) -> Self {
117+
pub fn new(validator: Arc<V>, ordering: Arc<T>, config: PoolConfig) -> Self {
118118
Self {
119119
identifiers: Default::default(),
120-
validator: client,
121-
config,
120+
validator,
122121
event_listener: Default::default(),
123-
pool: RwLock::new(TxPool::new(ordering)),
122+
pool: RwLock::new(TxPool::new(ordering, config.clone())),
124123
pending_transaction_listener: Default::default(),
125124
transaction_listener: Default::default(),
125+
config,
126126
}
127127
}
128128

crates/transaction-pool/src/pool/txpool.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The internal transaction pool implementation.
22
use 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
};
1415
use fnv::FnvHashMap;
1516
use 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

8588
impl<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

324330
impl<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> {
588599
impl<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,

crates/transaction-pool/src/test_util/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub type MockValidTx = ValidPoolTransaction<MockTransaction>;
1919

2020
/// Create an empty `TxPool`
2121
pub fn mock_tx_pool() -> MockTxPool {
22-
MockTxPool::new(Arc::new(Default::default()))
22+
MockTxPool::new(Arc::new(Default::default()), Default::default())
2323
}
2424

2525
/// Sets the value for the field

crates/transaction-pool/src/test_util/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl MockPool {
4141

4242
impl Default for MockPool {
4343
fn default() -> Self {
44-
Self { pool: TxPool::new(Arc::new(MockOrdering::default())) }
44+
Self { pool: TxPool::new(Arc::new(MockOrdering::default()), Default::default()) }
4545
}
4646
}
4747

0 commit comments

Comments
 (0)