Skip to content

Commit

Permalink
chore: rm v2 get bodies functions (#11870)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 18, 2024
1 parent 8d32fd7 commit 9c8f5d8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 123 deletions.
23 changes: 3 additions & 20 deletions crates/rpc/rpc-api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use alloy_rpc_types::{
state::StateOverride, BlockOverrides, EIP1186AccountProofResponse, Filter, Log, SyncStatus,
};
use alloy_rpc_types_engine::{
ClientVersionV1, ExecutionPayloadBodiesV1, ExecutionPayloadBodiesV2, ExecutionPayloadInputV2,
ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4, ForkchoiceState, ForkchoiceUpdated,
PayloadId, PayloadStatus, TransitionConfiguration,
ClientVersionV1, ExecutionPayloadBodiesV1, ExecutionPayloadInputV2, ExecutionPayloadV1,
ExecutionPayloadV3, ExecutionPayloadV4, ForkchoiceState, ForkchoiceUpdated, PayloadId,
PayloadStatus, TransitionConfiguration,
};
use alloy_rpc_types_eth::transaction::TransactionRequest;
use alloy_serde::JsonStorageKey;
Expand Down Expand Up @@ -146,13 +146,6 @@ pub trait EngineApi<Engine: EngineTypes> {
block_hashes: Vec<BlockHash>,
) -> RpcResult<ExecutionPayloadBodiesV1>;

/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md#engine_getpayloadbodiesbyhashv2>
#[method(name = "getPayloadBodiesByHashV2")]
async fn get_payload_bodies_by_hash_v2(
&self,
block_hashes: Vec<BlockHash>,
) -> RpcResult<ExecutionPayloadBodiesV2>;

/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#engine_getpayloadbodiesbyrangev1>
///
/// Returns the execution payload bodies by the range starting at `start`, containing `count`
Expand All @@ -172,16 +165,6 @@ pub trait EngineApi<Engine: EngineTypes> {
count: U64,
) -> RpcResult<ExecutionPayloadBodiesV1>;

/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md#engine_getpayloadbodiesbyrangev2>
///
/// Similar to `getPayloadBodiesByRangeV1`, but returns [`ExecutionPayloadBodiesV2`]
#[method(name = "getPayloadBodiesByRangeV2")]
async fn get_payload_bodies_by_range_v2(
&self,
start: U64,
count: U64,
) -> RpcResult<ExecutionPayloadBodiesV2>;

/// See also <https://github.com/ethereum/execution-apis/blob/6709c2a795b707202e93c4f2867fa0bf2640a84f/src/engine/paris.md#engine_exchangetransitionconfigurationv1>
///
/// Note: This method will be deprecated after the cancun hardfork:
Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc-engine-api/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ pub const CAPABILITIES: &[&str] = &[
"engine_newPayloadV4",
"engine_getPayloadBodiesByHashV1",
"engine_getPayloadBodiesByRangeV1",
"engine_getPayloadBodiesByHashV2",
"engine_getPayloadBodiesByRangeV2",
"engine_getBlobsV1",
];

Expand Down
52 changes: 3 additions & 49 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use alloy_eips::eip4844::BlobAndProofV1;
use alloy_primitives::{BlockHash, BlockNumber, B256, U64};
use alloy_rpc_types_engine::{
CancunPayloadFields, ClientVersionV1, ExecutionPayload, ExecutionPayloadBodiesV1,
ExecutionPayloadBodiesV2, ExecutionPayloadInputV2, ExecutionPayloadV1, ExecutionPayloadV3,
ExecutionPayloadV4, ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus,
TransitionConfiguration,
ExecutionPayloadInputV2, ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4,
ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus, TransitionConfiguration,
};
use async_trait::async_trait;
use jsonrpsee_core::RpcResult;
Expand All @@ -23,7 +22,7 @@ use reth_payload_primitives::{
use reth_primitives::{Block, BlockHashOrNumber, EthereumHardfork};
use reth_rpc_api::EngineApiServer;
use reth_rpc_types_compat::engine::payload::{
convert_payload_input_v2_to_payload, convert_to_payload_body_v1, convert_to_payload_body_v2,
convert_payload_input_v2_to_payload, convert_to_payload_body_v1,
};
use reth_storage_api::{BlockReader, HeaderProvider, StateProviderFactory};
use reth_tasks::TaskSpawner;
Expand Down Expand Up @@ -451,18 +450,6 @@ where
self.get_payload_bodies_by_range_with(start, count, convert_to_payload_body_v1).await
}

/// Returns the execution payload bodies by the range starting at `start`, containing `count`
/// blocks.
///
/// Same as [`Self::get_payload_bodies_by_range_v1`] but as [`ExecutionPayloadBodiesV2`].
pub async fn get_payload_bodies_by_range_v2(
&self,
start: BlockNumber,
count: u64,
) -> EngineApiResult<ExecutionPayloadBodiesV2> {
self.get_payload_bodies_by_range_with(start, count, convert_to_payload_body_v2).await
}

/// Called to retrieve execution payload bodies by hashes.
async fn get_payload_bodies_by_hash_with<F, R>(
&self,
Expand Down Expand Up @@ -509,16 +496,6 @@ where
self.get_payload_bodies_by_hash_with(hashes, convert_to_payload_body_v1).await
}

/// Called to retrieve execution payload bodies by hashes.
///
/// Same as [`Self::get_payload_bodies_by_hash_v1`] but as [`ExecutionPayloadBodiesV2`].
pub async fn get_payload_bodies_by_hash_v2(
&self,
hashes: Vec<BlockHash>,
) -> EngineApiResult<ExecutionPayloadBodiesV2> {
self.get_payload_bodies_by_hash_with(hashes, convert_to_payload_body_v2).await
}

/// Called to verify network configuration parameters and ensure that Consensus and Execution
/// layers are using the latest configuration.
pub fn exchange_transition_configuration(
Expand Down Expand Up @@ -846,17 +823,6 @@ where
Ok(res.await?)
}

async fn get_payload_bodies_by_hash_v2(
&self,
block_hashes: Vec<BlockHash>,
) -> RpcResult<ExecutionPayloadBodiesV2> {
trace!(target: "rpc::engine", "Serving engine_getPayloadBodiesByHashV2");
let start = Instant::now();
let res = Self::get_payload_bodies_by_hash_v2(self, block_hashes);
self.inner.metrics.latency.get_payload_bodies_by_hash_v2.record(start.elapsed());
Ok(res.await?)
}

/// Handler for `engine_getPayloadBodiesByRangeV1`
///
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#engine_getpayloadbodiesbyrangev1>
Expand Down Expand Up @@ -885,18 +851,6 @@ where
Ok(res?)
}

async fn get_payload_bodies_by_range_v2(
&self,
start: U64,
count: U64,
) -> RpcResult<ExecutionPayloadBodiesV2> {
trace!(target: "rpc::engine", "Serving engine_getPayloadBodiesByRangeV2");
let start_time = Instant::now();
let res = Self::get_payload_bodies_by_range_v2(self, start.to(), count.to()).await;
self.inner.metrics.latency.get_payload_bodies_by_range_v2.record(start_time.elapsed());
Ok(res?)
}

/// Handler for `engine_exchangeTransitionConfigurationV1`
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/paris.md#engine_exchangeTransitionConfigurationV1>
async fn exchange_transition_configuration(
Expand Down
4 changes: 0 additions & 4 deletions crates/rpc/rpc-engine-api/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ pub(crate) struct EngineApiLatencyMetrics {
pub(crate) get_payload_v4: Histogram,
/// Latency for `engine_getPayloadBodiesByRangeV1`
pub(crate) get_payload_bodies_by_range_v1: Histogram,
/// Latency for `engine_getPayloadBodiesByRangeV2`
pub(crate) get_payload_bodies_by_range_v2: Histogram,
/// Latency for `engine_getPayloadBodiesByHashV1`
pub(crate) get_payload_bodies_by_hash_v1: Histogram,
/// Latency for `engine_getPayloadBodiesByHashV2`
pub(crate) get_payload_bodies_by_hash_v2: Histogram,
/// Latency for `engine_exchangeTransitionConfigurationV1`
pub(crate) exchange_transition_configuration: Histogram,
}
Expand Down
50 changes: 2 additions & 48 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{B256, U256};
use alloy_rpc_types_engine::{
payload::{ExecutionPayloadBodyV1, ExecutionPayloadFieldV2, ExecutionPayloadInputV2},
ExecutionPayload, ExecutionPayloadBodyV2, ExecutionPayloadV1, ExecutionPayloadV2,
ExecutionPayloadV3, ExecutionPayloadV4, PayloadError,
ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
ExecutionPayloadV4, PayloadError,
};
use reth_primitives::{
constants::MAXIMUM_EXTRA_DATA_SIZE,
Expand Down Expand Up @@ -381,52 +381,6 @@ pub fn convert_to_payload_body_v1(value: Block) -> ExecutionPayloadBodyV1 {
}
}

/// Converts [`Block`] to [`ExecutionPayloadBodyV2`]
pub fn convert_to_payload_body_v2(value: Block) -> ExecutionPayloadBodyV2 {
let transactions = value.body.transactions.into_iter().map(|tx| {
let mut out = Vec::new();
tx.encode_2718(&mut out);
out.into()
});

let mut payload = ExecutionPayloadBodyV2 {
transactions: transactions.collect(),
withdrawals: value.body.withdrawals.map(Withdrawals::into_inner),
deposit_requests: None,
withdrawal_requests: None,
consolidation_requests: None,
};

if let Some(requests) = value.body.requests {
let (deposit_requests, withdrawal_requests, consolidation_requests) =
requests.into_iter().fold(
(Vec::new(), Vec::new(), Vec::new()),
|(mut deposits, mut withdrawals, mut consolidation_requests), request| {
match request {
Request::DepositRequest(r) => {
deposits.push(r);
}
Request::WithdrawalRequest(r) => {
withdrawals.push(r);
}
Request::ConsolidationRequest(r) => {
consolidation_requests.push(r);
}
_ => {}
};

(deposits, withdrawals, consolidation_requests)
},
);

payload.deposit_requests = Some(deposit_requests);
payload.withdrawal_requests = Some(withdrawal_requests);
payload.consolidation_requests = Some(consolidation_requests);
}

payload
}

/// Transforms a [`SealedBlock`] into a [`ExecutionPayloadV1`]
pub fn execution_payload_from_sealed_block(value: SealedBlock) -> ExecutionPayloadV1 {
let transactions = value.raw_transactions();
Expand Down

0 comments on commit 9c8f5d8

Please sign in to comment.