feat: add engine api types and interface

This commit is contained in:
Matthias Seitz
2022-10-03 15:31:08 +02:00
parent 8b7bef4f48
commit 9251b286d0
4 changed files with 128 additions and 2 deletions

View File

@ -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 <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_newpayloadv1>
#[method(name = "engine_newPayloadV1")]
async fn new_payload(&self, payload: ExecutionPayload) -> Result<PayloadStatus>;
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_forkchoiceUpdatedV1>
#[method(name = "engine_forkchoiceUpdatedV1")]
async fn fork_choice_updated(
&self,
fork_choice_state: ForkchoiceState,
payload_attributes: Option<PayloadAttributes>,
) -> Result<ForkchoiceUpdated>;
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_getPayloadV1>
#[method(name = "engine_getPayloadV1")]
async fn get_payload(&self, payload_id: H64) -> Result<ExecutionPayload>;
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_exchangeTransitionConfigurationV1>
#[method(name = "engine_exchangeTransitionConfigurationV1")]
async fn exchange_transition_configuration(
&self,
transition_configuration: TransitionConfiguration,
) -> Result<TransitionConfiguration>;
}

View File

@ -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,
};

View File

@ -0,0 +1,88 @@
#![allow(missing_docs)]
//! Engine API types: <https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md>
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<Bytes>,
}
/// 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<H256>,
}
#[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<H64>,
}

View File

@ -3,6 +3,7 @@
mod account;
mod block;
mod call;
pub mod engine;
mod fee;
mod filter;
mod index;