reth_node_builder/components/
pool.rsuse alloy_primitives::Address;
use reth_node_api::TxTy;
use reth_transaction_pool::{PoolConfig, PoolTransaction, SubPoolLimit, TransactionPool};
use std::{collections::HashSet, future::Future};
use crate::{BuilderContext, FullNodeTypes};
pub trait PoolBuilder<Node: FullNodeTypes>: Send {
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static;
fn build_pool(
self,
ctx: &BuilderContext<Node>,
) -> impl Future<Output = eyre::Result<Self::Pool>> + Send;
}
impl<Node, F, Fut, Pool> PoolBuilder<Node> for F
where
Node: FullNodeTypes,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<Pool>> + Send,
{
type Pool = Pool;
fn build_pool(
self,
ctx: &BuilderContext<Node>,
) -> impl Future<Output = eyre::Result<Self::Pool>> {
self(ctx)
}
}
#[derive(Debug, Clone, Default)]
pub struct PoolBuilderConfigOverrides {
pub pending_limit: Option<SubPoolLimit>,
pub basefee_limit: Option<SubPoolLimit>,
pub queued_limit: Option<SubPoolLimit>,
pub blob_limit: Option<SubPoolLimit>,
pub max_account_slots: Option<usize>,
pub minimal_protocol_basefee: Option<u64>,
pub local_addresses: HashSet<Address>,
pub additional_validation_tasks: Option<usize>,
}
impl PoolBuilderConfigOverrides {
pub fn apply(self, mut config: PoolConfig) -> PoolConfig {
let Self {
pending_limit,
basefee_limit,
queued_limit,
blob_limit,
max_account_slots,
minimal_protocol_basefee,
local_addresses,
additional_validation_tasks: _,
} = self;
if let Some(pending_limit) = pending_limit {
config.pending_limit = pending_limit;
}
if let Some(basefee_limit) = basefee_limit {
config.basefee_limit = basefee_limit;
}
if let Some(queued_limit) = queued_limit {
config.queued_limit = queued_limit;
}
if let Some(blob_limit) = blob_limit {
config.blob_limit = blob_limit;
}
if let Some(max_account_slots) = max_account_slots {
config.max_account_slots = max_account_slots;
}
if let Some(minimal_protocol_basefee) = minimal_protocol_basefee {
config.minimal_protocol_basefee = minimal_protocol_basefee;
}
config.local_transactions_config.local_addresses.extend(local_addresses);
config
}
}