use crate::ConfigureEvm;
use alloy_rpc_types_engine::JwtSecret;
use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_consensus::FullConsensus;
use reth_db_api::{
database_metrics::{DatabaseMetadata, DatabaseMetrics},
Database,
};
use reth_evm::execute::BlockExecutorProvider;
use reth_network_api::FullNetwork;
use reth_node_core::node_config::NodeConfig;
use reth_node_types::{HeaderTy, NodeTypes, NodeTypesWithDBAdapter, NodeTypesWithEngine, TxTy};
use reth_payload_builder_primitives::PayloadBuilder;
use reth_provider::FullProvider;
use reth_tasks::TaskExecutor;
use reth_transaction_pool::{PoolTransaction, TransactionPool};
use std::{future::Future, marker::PhantomData};
pub trait FullNodeTypes: Send + Sync + Unpin + 'static {
type Types: NodeTypesWithEngine;
type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static;
type Provider: FullProvider<NodeTypesWithDBAdapter<Self::Types, Self::DB>>;
}
#[derive(Debug)]
pub struct FullNodeTypesAdapter<Types, DB, Provider>(PhantomData<(Types, DB, Provider)>);
impl<Types, DB, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
where
Types: NodeTypesWithEngine,
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
Provider: FullProvider<NodeTypesWithDBAdapter<Types, DB>>,
{
type Types = Types;
type DB = DB;
type Provider = Provider;
}
pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Types>>> + Unpin;
type Evm: ConfigureEvm<Header = HeaderTy<Self::Types>, Transaction = TxTy<Self::Types>>;
type Executor: BlockExecutorProvider<Primitives = <Self::Types as NodeTypes>::Primitives>;
type Consensus: FullConsensus<<Self::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static;
type Network: FullNetwork;
type PayloadBuilder: PayloadBuilder<PayloadType = <Self::Types as NodeTypesWithEngine>::Engine>
+ 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(())
}
}