1use crate::PayloadTypes;
4use alloy_rpc_types_engine::JwtSecret;
5use reth_basic_payload_builder::PayloadBuilder;
6use reth_consensus::{ConsensusError, FullConsensus};
7use reth_db_api::{database_metrics::DatabaseMetrics, Database};
8use reth_engine_primitives::{BeaconConsensusEngineEvent, BeaconConsensusEngineHandle};
9use reth_evm::ConfigureEvm;
10use reth_network_api::FullNetwork;
11use reth_node_core::node_config::NodeConfig;
12use reth_node_types::{NodeTypes, NodeTypesWithDBAdapter, TxTy};
13use reth_payload_builder::PayloadBuilderHandle;
14use reth_provider::FullProvider;
15use reth_tasks::TaskExecutor;
16use reth_tokio_util::EventSender;
17use reth_transaction_pool::{PoolTransaction, TransactionPool};
18use std::{fmt::Debug, future::Future, marker::PhantomData};
19
20pub trait FullNodeTypes: Clone + Debug + Send + Sync + Unpin + 'static {
25 type Types: NodeTypes;
27 type DB: Database + DatabaseMetrics + Clone + Unpin + 'static;
29 type Provider: FullProvider<NodeTypesWithDBAdapter<Self::Types, Self::DB>>;
31}
32
33#[derive(Clone, Debug)]
35pub struct FullNodeTypesAdapter<Types, DB, Provider>(PhantomData<(Types, DB, Provider)>);
36
37impl<Types, DB, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
38where
39 Types: NodeTypes,
40 DB: Database + DatabaseMetrics + Clone + Unpin + 'static,
41 Provider: FullProvider<NodeTypesWithDBAdapter<Types, DB>>,
42{
43 type Types = Types;
44 type DB = DB;
45 type Provider = Provider;
46}
47
48pub trait PayloadBuilderFor<N: NodeTypes>:
50 PayloadBuilder<
51 Attributes = <N::Payload as PayloadTypes>::PayloadBuilderAttributes,
52 BuiltPayload = <N::Payload as PayloadTypes>::BuiltPayload,
53>
54{
55}
56
57impl<T, N: NodeTypes> PayloadBuilderFor<N> for T where
58 T: PayloadBuilder<
59 Attributes = <N::Payload as PayloadTypes>::PayloadBuilderAttributes,
60 BuiltPayload = <N::Payload as PayloadTypes>::BuiltPayload,
61 >
62{
63}
64
65pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
67 type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Types>>> + Unpin;
69
70 type Evm: ConfigureEvm<Primitives = <Self::Types as NodeTypes>::Primitives>;
72
73 type Consensus: FullConsensus<<Self::Types as NodeTypes>::Primitives, Error = ConsensusError>
75 + Clone
76 + Unpin
77 + 'static;
78
79 type Network: FullNetwork;
81
82 fn pool(&self) -> &Self::Pool;
84
85 fn evm_config(&self) -> &Self::Evm;
87
88 fn consensus(&self) -> &Self::Consensus;
90
91 fn network(&self) -> &Self::Network;
93
94 fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<Self::Types as NodeTypes>::Payload>;
97
98 fn provider(&self) -> &Self::Provider;
100
101 fn task_executor(&self) -> &TaskExecutor;
106}
107
108#[derive(Debug, Clone)]
110pub struct AddOnsContext<'a, N: FullNodeComponents> {
111 pub node: N,
113 pub config: &'a NodeConfig<<N::Types as NodeTypes>::ChainSpec>,
115 pub beacon_engine_handle: BeaconConsensusEngineHandle<<N::Types as NodeTypes>::Payload>,
117 pub engine_events: EventSender<BeaconConsensusEngineEvent<<N::Types as NodeTypes>::Primitives>>,
119 pub jwt_secret: JwtSecret,
121}
122
123pub trait NodeAddOns<N: FullNodeComponents>: Send {
125 type Handle: Send + Sync + Clone;
127
128 fn launch_add_ons(
130 self,
131 ctx: AddOnsContext<'_, N>,
132 ) -> impl Future<Output = eyre::Result<Self::Handle>> + Send;
133}
134
135impl<N: FullNodeComponents> NodeAddOns<N> for () {
136 type Handle = ();
137
138 async fn launch_add_ons(self, _components: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
139 Ok(())
140 }
141}