reth_optimism_node/
rpc.rs

1//! RPC component builder
2
3pub use reth_optimism_rpc::OpEngineApi;
4
5use crate::OP_NAME_CLIENT;
6use alloy_rpc_types_engine::ClientVersionV1;
7use op_alloy_rpc_types_engine::OpExecutionData;
8use reth_chainspec::EthereumHardforks;
9use reth_node_api::{
10    AddOnsContext, EngineTypes, FullNodeComponents, NodeTypes, NodeTypesWithEngine,
11};
12use reth_node_builder::rpc::{EngineApiBuilder, EngineValidatorBuilder};
13use reth_node_core::version::{CARGO_PKG_VERSION, CLIENT_CODE, VERGEN_GIT_SHA};
14use reth_optimism_rpc::engine::OP_ENGINE_CAPABILITIES;
15use reth_payload_builder::PayloadStore;
16use reth_rpc_engine_api::{EngineApi, EngineCapabilities};
17
18/// Builder for basic [`OpEngineApi`] implementation.
19#[derive(Debug, Default)]
20pub struct OpEngineApiBuilder<EV> {
21    engine_validator_builder: EV,
22}
23
24impl<N, EV> EngineApiBuilder<N> for OpEngineApiBuilder<EV>
25where
26    N: FullNodeComponents<
27        Types: NodeTypesWithEngine<
28            ChainSpec: EthereumHardforks,
29            Engine: EngineTypes<ExecutionData = OpExecutionData>,
30        >,
31    >,
32    EV: EngineValidatorBuilder<N>,
33{
34    type EngineApi = OpEngineApi<
35        N::Provider,
36        <N::Types as NodeTypesWithEngine>::Engine,
37        N::Pool,
38        EV::Validator,
39        <N::Types as NodeTypes>::ChainSpec,
40    >;
41
42    async fn build_engine_api(self, ctx: &AddOnsContext<'_, N>) -> eyre::Result<Self::EngineApi> {
43        let Self { engine_validator_builder } = self;
44
45        let engine_validator = engine_validator_builder.build(ctx).await?;
46        let client = ClientVersionV1 {
47            code: CLIENT_CODE,
48            name: OP_NAME_CLIENT.to_string(),
49            version: CARGO_PKG_VERSION.to_string(),
50            commit: VERGEN_GIT_SHA.to_string(),
51        };
52        let inner = EngineApi::new(
53            ctx.node.provider().clone(),
54            ctx.config.chain.clone(),
55            ctx.beacon_engine_handle.clone(),
56            PayloadStore::new(ctx.node.payload_builder_handle().clone()),
57            ctx.node.pool().clone(),
58            Box::new(ctx.node.task_executor().clone()),
59            client,
60            EngineCapabilities::new(OP_ENGINE_CAPABILITIES.iter().copied()),
61            engine_validator,
62        );
63
64        Ok(OpEngineApi::new(inner))
65    }
66}