diff --git a/crates/net/rpc-api/src/engine.rs b/crates/net/rpc-api/src/engine.rs new file mode 100644 index 000000000..53385f1e6 --- /dev/null +++ b/crates/net/rpc-api/src/engine.rs @@ -0,0 +1,35 @@ +use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use reth_primitives::{BlockId, Bytes, H256, H64}; +use reth_rpc_types::{ + engine::{ + ExecutionPayload, ForkchoiceState, ForkchoiceUpdated, PayloadAttributes, PayloadStatus, + TransitionConfiguration, + }, + RichBlock, +}; + +#[rpc(client)] +pub trait EngineApi { + /// See also + #[method(name = "engine_newPayloadV1")] + async fn new_payload(&self, payload: ExecutionPayload) -> Result; + + /// See also + #[method(name = "engine_forkchoiceUpdatedV1")] + async fn fork_choice_updated( + &self, + fork_choice_state: ForkchoiceState, + payload_attributes: Option, + ) -> Result; + + /// See also + #[method(name = "engine_getPayloadV1")] + async fn get_payload(&self, payload_id: H64) -> Result; + + /// See also + #[method(name = "engine_exchangeTransitionConfigurationV1")] + async fn exchange_transition_configuration( + &self, + transition_configuration: TransitionConfiguration, + ) -> Result; +} diff --git a/crates/net/rpc-api/src/lib.rs b/crates/net/rpc-api/src/lib.rs index 24a7d3615..4da4cbeea 100644 --- a/crates/net/rpc-api/src/lib.rs +++ b/crates/net/rpc-api/src/lib.rs @@ -10,6 +10,7 @@ //! Provides all RPC interfaces. mod debug; +mod engine; mod eth; mod eth_filter; mod eth_pubsub; @@ -18,6 +19,7 @@ mod trace; mod web3; pub use self::{ - debug::DebugApiServer, eth::EthApiServer, eth_filter::EthFilterApiServer, - eth_pubsub::EthPubSubApiServer, net::NetApiServer, web3::Web3ApiServer, + debug::DebugApiServer, engine::EngineApiServer, eth::EthApiServer, + eth_filter::EthFilterApiServer, eth_pubsub::EthPubSubApiServer, net::NetApiServer, + web3::Web3ApiServer, }; diff --git a/crates/net/rpc-types/src/eth/engine.rs b/crates/net/rpc-types/src/eth/engine.rs new file mode 100644 index 000000000..89d47ce66 --- /dev/null +++ b/crates/net/rpc-types/src/eth/engine.rs @@ -0,0 +1,88 @@ +#![allow(missing_docs)] +//! Engine API types: + +use reth_primitives::{Address, BlockNumber, Bloom, Bytes, H256, H64, U256, U64}; + +/// This structure maps on the ExecutionPayload structure of the beacon chain spec. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ExecutionPayload { + pub parent_hash: H256, + pub fee_recipient: Address, + pub state_root: H256, + pub receipts_root: H256, + pub logs_bloom: Bloom, + pub prev_randao: H256, + pub block_number: U64, + pub gas_limit: U64, + pub gas_used: U64, + pub timestamp: U64, + pub extra_data: Bytes, + pub base_fee_per_gas: U256, + pub block_hash: H256, + pub transactions: Vec, +} + +/// This structure encapsulates the fork choice state +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ForkchoiceState { + pub head_block_hash: H256, + pub safe_block_hash: H256, + pub finalized_block_hash: H256, +} + +/// This structure contains the attributes required to initiate a payload build process in the +/// context of an `engine_forkchoiceUpdated` call. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PayloadAttributes { + pub timestamp: U64, + pub prev_randao: H256, + pub suggested_fee_recipient: Address, +} + +/// This structure contains the result of processing a payload +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct PayloadStatus { + #[serde(flatten)] + pub status: PayloadStatusEnum, + /// Hash of the most recent valid block in the branch defined by payload and its ancestors + pub latest_valid_hash: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(tag = "status", rename_all = "SCREAMING_SNAKE_CASE")] +pub enum PayloadStatusEnum { + Valid, + Invalid { + #[serde(rename = "validationError")] + validation_error: String, + }, + Syncing, + Accepted, + InvalidBlockHash { + #[serde(rename = "validationError")] + validation_error: String, + }, +} + +/// This structure contains configurable settings of the transition process. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TransitionConfiguration { + /// maps on the TERMINAL_TOTAL_DIFFICULTY parameter of EIP-3675 + pub terminal_total_difficulty: U256, + /// maps on TERMINAL_BLOCK_HASH parameter of EIP-3675 + pub terminal_block_hash: H256, + /// maps on TERMINAL_BLOCK_NUMBER parameter of EIP-3675 + pub terminal_block_number: BlockNumber, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ForkchoiceUpdated { + pub payload_status: PayloadStatus, + pub payload_id: Option, +} diff --git a/crates/net/rpc-types/src/eth/mod.rs b/crates/net/rpc-types/src/eth/mod.rs index 562bedfc2..2ea643335 100644 --- a/crates/net/rpc-types/src/eth/mod.rs +++ b/crates/net/rpc-types/src/eth/mod.rs @@ -3,6 +3,7 @@ mod account; mod block; mod call; +pub mod engine; mod fee; mod filter; mod index;