reth_node_builder/components/
pool.rs
1use alloy_primitives::Address;
4use reth_node_api::TxTy;
5use reth_transaction_pool::{PoolConfig, PoolTransaction, SubPoolLimit, TransactionPool};
6use std::{collections::HashSet, future::Future};
7
8use crate::{BuilderContext, FullNodeTypes};
9
10pub trait PoolBuilder<Node: FullNodeTypes>: Send {
12 type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
14 + Unpin
15 + 'static;
16
17 fn build_pool(
19 self,
20 ctx: &BuilderContext<Node>,
21 ) -> impl Future<Output = eyre::Result<Self::Pool>> + Send;
22}
23
24impl<Node, F, Fut, Pool> PoolBuilder<Node> for F
25where
26 Node: FullNodeTypes,
27 Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
28 + Unpin
29 + 'static,
30 F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
31 Fut: Future<Output = eyre::Result<Pool>> + Send,
32{
33 type Pool = Pool;
34
35 fn build_pool(
36 self,
37 ctx: &BuilderContext<Node>,
38 ) -> impl Future<Output = eyre::Result<Self::Pool>> {
39 self(ctx)
40 }
41}
42
43#[derive(Debug, Clone, Default)]
45pub struct PoolBuilderConfigOverrides {
46 pub pending_limit: Option<SubPoolLimit>,
48 pub basefee_limit: Option<SubPoolLimit>,
50 pub queued_limit: Option<SubPoolLimit>,
52 pub blob_limit: Option<SubPoolLimit>,
54 pub max_account_slots: Option<usize>,
56 pub minimal_protocol_basefee: Option<u64>,
58 pub local_addresses: HashSet<Address>,
60 pub additional_validation_tasks: Option<usize>,
62}
63
64impl PoolBuilderConfigOverrides {
65 pub fn apply(self, mut config: PoolConfig) -> PoolConfig {
67 let Self {
68 pending_limit,
69 basefee_limit,
70 queued_limit,
71 blob_limit,
72 max_account_slots,
73 minimal_protocol_basefee,
74 local_addresses,
75 additional_validation_tasks: _,
76 } = self;
77
78 if let Some(pending_limit) = pending_limit {
79 config.pending_limit = pending_limit;
80 }
81 if let Some(basefee_limit) = basefee_limit {
82 config.basefee_limit = basefee_limit;
83 }
84 if let Some(queued_limit) = queued_limit {
85 config.queued_limit = queued_limit;
86 }
87 if let Some(blob_limit) = blob_limit {
88 config.blob_limit = blob_limit;
89 }
90 if let Some(max_account_slots) = max_account_slots {
91 config.max_account_slots = max_account_slots;
92 }
93 if let Some(minimal_protocol_basefee) = minimal_protocol_basefee {
94 config.minimal_protocol_basefee = minimal_protocol_basefee;
95 }
96 config.local_transactions_config.local_addresses.extend(local_addresses);
97
98 config
99 }
100}