reth_node_builder/components/
pool.rs

1//! Pool component for the node builder.
2
3use 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
10/// A type that knows how to build the transaction pool.
11pub trait PoolBuilder<Node: FullNodeTypes>: Send {
12    /// The transaction pool to build.
13    type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
14        + Unpin
15        + 'static;
16
17    /// Creates the transaction pool.
18    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/// Convenience type to override cli or default pool configuration during build.
44#[derive(Debug, Clone, Default)]
45pub struct PoolBuilderConfigOverrides {
46    /// Max number of transaction in the pending sub-pool
47    pub pending_limit: Option<SubPoolLimit>,
48    /// Max number of transaction in the basefee sub-pool
49    pub basefee_limit: Option<SubPoolLimit>,
50    /// Max number of transaction in the queued sub-pool
51    pub queued_limit: Option<SubPoolLimit>,
52    /// Max number of transactions in the blob sub-pool
53    pub blob_limit: Option<SubPoolLimit>,
54    /// Max number of executable transaction slots guaranteed per account
55    pub max_account_slots: Option<usize>,
56    /// Minimum base fee required by the protocol.
57    pub minimal_protocol_basefee: Option<u64>,
58    /// Addresses that will be considered as local. Above exemptions apply.
59    pub local_addresses: HashSet<Address>,
60    /// Additional tasks to validate new transactions.
61    pub additional_validation_tasks: Option<usize>,
62}
63
64impl PoolBuilderConfigOverrides {
65    /// Applies the configured overrides to the given [`PoolConfig`].
66    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}