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