use crate::ConfigureEvm;
use alloy_consensus::Header;
use alloy_rpc_types_engine::JwtSecret;
use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_consensus::Consensus;
use reth_evm::execute::BlockExecutorProvider;
use reth_network_api::FullNetwork;
use reth_node_core::node_config::NodeConfig;
use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine};
use reth_payload_primitives::PayloadBuilder;
use reth_provider::FullProvider;
use reth_tasks::TaskExecutor;
use reth_transaction_pool::TransactionPool;
use std::{future::Future, marker::PhantomData};
pub trait FullNodeTypes: Send + Sync + Unpin + 'static {
type Types: NodeTypesWithDB + NodeTypesWithEngine;
type Provider: FullProvider<Self::Types>;
}
#[derive(Debug)]
pub struct FullNodeTypesAdapter<Types, Provider> {
pub types: PhantomData<Types>,
pub provider: PhantomData<Provider>,
}
impl<Types, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, Provider>
where
Types: NodeTypesWithDB + NodeTypesWithEngine,
Provider: FullProvider<Types>,
{
type Types = Types;
type Provider = Provider;
}
pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
type Pool: TransactionPool + Unpin;
type Evm: ConfigureEvm<Header = Header>;
type Executor: BlockExecutorProvider;
type Consensus: Consensus + Clone + Unpin + 'static;
type Network: FullNetwork;
type PayloadBuilder: PayloadBuilder + Clone;
fn pool(&self) -> &Self::Pool;
fn evm_config(&self) -> &Self::Evm;
fn block_executor(&self) -> &Self::Executor;
fn consensus(&self) -> &Self::Consensus;
fn network(&self) -> &Self::Network;
fn payload_builder(&self) -> &Self::PayloadBuilder;
fn provider(&self) -> &Self::Provider;
fn task_executor(&self) -> &TaskExecutor;
}
#[derive(Debug, Clone)]
pub struct AddOnsContext<'a, N: FullNodeComponents> {
pub node: N,
pub config: &'a NodeConfig<<N::Types as NodeTypes>::ChainSpec>,
pub beacon_engine_handle:
BeaconConsensusEngineHandle<<N::Types as NodeTypesWithEngine>::Engine>,
pub jwt_secret: JwtSecret,
}
pub trait NodeAddOns<N: FullNodeComponents>: Send {
type Handle: Send + Sync + Clone;
fn launch_add_ons(
self,
ctx: AddOnsContext<'_, N>,
) -> impl Future<Output = eyre::Result<Self::Handle>> + Send;
}
impl<N: FullNodeComponents> NodeAddOns<N> for () {
type Handle = ();
async fn launch_add_ons(self, _components: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
Ok(())
}
}