From a43a6cba8c551a6c4267fd89109d3df95ff07510 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 28 Nov 2022 14:18:43 +0100 Subject: [PATCH] feat(rpc): add new engine V2 types and routes (#274) --- crates/net/rpc-api/src/engine.rs | 27 +++++++++++++++++--- crates/net/rpc-types/src/eth/engine.rs | 34 +++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/crates/net/rpc-api/src/engine.rs b/crates/net/rpc-api/src/engine.rs index 1bed3351cc..af0c098b49 100644 --- a/crates/net/rpc-api/src/engine.rs +++ b/crates/net/rpc-api/src/engine.rs @@ -9,20 +9,41 @@ use reth_rpc_types::engine::{ #[cfg_attr(feature = "client", rpc(server, client))] pub trait EngineApi { /// See also + /// Caution: This should not accept the `withdrawals` field #[method(name = "engine_newPayloadV1")] - async fn new_payload(&self, payload: ExecutionPayload) -> Result; + async fn new_payload_v1(&self, payload: ExecutionPayload) -> Result; + + /// See also + #[method(name = "engine_newPayloadV2")] + async fn new_payload_v2(&self, payload: ExecutionPayload) -> Result; /// See also + /// + /// Caution: This should not accept the `withdrawals` field #[method(name = "engine_forkchoiceUpdatedV1")] - async fn fork_choice_updated( + async fn fork_choice_updated_v1( + &self, + fork_choice_state: ForkchoiceState, + payload_attributes: Option, + ) -> Result; + + /// See also + #[method(name = "engine_forkchoiceUpdatedV2")] + async fn fork_choice_updated_v2( &self, fork_choice_state: ForkchoiceState, payload_attributes: Option, ) -> Result; /// See also + /// + /// Caution: This should not return the `withdrawals` field #[method(name = "engine_getPayloadV1")] - async fn get_payload(&self, payload_id: H64) -> Result; + async fn get_payload_v1(&self, payload_id: H64) -> Result; + + /// See also + #[method(name = "engine_getPayloadV2")] + async fn get_payload_v2(&self, payload_id: H64) -> Result; /// See also #[method(name = "engine_exchangeTransitionConfigurationV1")] diff --git a/crates/net/rpc-types/src/eth/engine.rs b/crates/net/rpc-types/src/eth/engine.rs index 85850f2326..68f2577773 100644 --- a/crates/net/rpc-types/src/eth/engine.rs +++ b/crates/net/rpc-types/src/eth/engine.rs @@ -1,10 +1,13 @@ +//! Engine API types: and following the execution spec + #![allow(missing_docs)] -//! Engine API types: use reth_primitives::{Address, BlockNumber, Bloom, Bytes, H256, H64, U256, U64}; use serde::{Deserialize, Serialize}; /// This structure maps on the ExecutionPayload structure of the beacon chain spec. +/// +/// See also: #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ExecutionPayload { @@ -22,6 +25,25 @@ pub struct ExecutionPayload { pub base_fee_per_gas: U256, pub block_hash: H256, pub transactions: Vec, + /// Array of [`Withdrawal`] enabled with V2 + /// See + #[serde(default, skip_serializing_if = "Option::is_none")] + pub withdrawal: Option, +} + +/// This structure maps onto the validator withdrawal object from the beacon chain spec. +/// +/// See also: +#[derive(Default, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Withdrawal { + pub index: U64, + pub validator_index: U64, + pub address: Address, + /// Note: the amount value is represented on the beacon chain as a little-endian value in units + /// of Gwei, whereas the amount in this structure MUST be converted to a big-endian value in + /// units of Wei. + pub amount: U256, } /// This structure encapsulates the fork choice state @@ -41,6 +63,10 @@ pub struct PayloadAttributes { pub timestamp: U64, pub prev_randao: H256, pub suggested_fee_recipient: Address, + /// Array of [`Withdrawal`] enabled with V2 + /// See + #[serde(default, skip_serializing_if = "Option::is_none")] + pub withdrawal: Option, } /// This structure contains the result of processing a payload @@ -73,11 +99,11 @@ pub enum PayloadStatusEnum { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct TransitionConfiguration { - /// maps on the TERMINAL_TOTAL_DIFFICULTY parameter of EIP-3675 + /// Maps on the TERMINAL_TOTAL_DIFFICULTY parameter of EIP-3675 pub terminal_total_difficulty: U256, - /// maps on TERMINAL_BLOCK_HASH parameter of EIP-3675 + /// Maps on TERMINAL_BLOCK_HASH parameter of EIP-3675 pub terminal_block_hash: H256, - /// maps on TERMINAL_BLOCK_NUMBER parameter of EIP-3675 + /// Maps on TERMINAL_BLOCK_NUMBER parameter of EIP-3675 pub terminal_block_number: BlockNumber, }