Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: convert_to_payload_body_v1 #14168

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rpc/rpc-engine-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ reth-payload-builder.workspace = true
reth-payload-builder-primitives.workspace = true
reth-payload-primitives.workspace = true
reth-tasks.workspace = true
reth-rpc-types-compat.workspace = true
reth-engine-primitives.workspace = true
reth-transaction-pool.workspace = true
reth-primitives-traits.workspace = true

# ethereum
alloy-eips.workspace = true
Expand Down
30 changes: 24 additions & 6 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ use crate::{
};
use alloy_eips::{
eip1898::BlockHashOrNumber,
eip2718::Encodable2718,
eip4844::BlobAndProofV1,
eip4895::Withdrawals,
eip7685::{Requests, RequestsOrHash},
};
use alloy_primitives::{BlockHash, BlockNumber, B256, U64};
use alloy_rpc_types_engine::{
CancunPayloadFields, ClientVersionV1, ExecutionPayload, ExecutionPayloadBodiesV1,
ExecutionPayloadInputV2, ExecutionPayloadSidecar, ExecutionPayloadV1, ExecutionPayloadV3,
ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus, PraguePayloadFields,
TransitionConfiguration,
ExecutionPayloadBodyV1, ExecutionPayloadInputV2, ExecutionPayloadSidecar, ExecutionPayloadV1,
ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus,
PraguePayloadFields, TransitionConfiguration,
};
use async_trait::async_trait;
use jsonrpsee_core::RpcResult;
Expand All @@ -23,8 +25,8 @@ use reth_payload_primitives::{
validate_payload_timestamp, EngineApiMessageVersion, PayloadBuilderAttributes,
PayloadOrAttributes,
};
use reth_primitives_traits::{Block, BlockBody};
use reth_rpc_api::EngineApiServer;
use reth_rpc_types_compat::engine::payload::convert_to_payload_body_v1;
use reth_storage_api::{BlockReader, HeaderProvider, StateProviderFactory};
use reth_tasks::TaskSpawner;
use reth_transaction_pool::TransactionPool;
Expand Down Expand Up @@ -551,7 +553,15 @@ where
start: BlockNumber,
count: u64,
) -> EngineApiResult<ExecutionPayloadBodiesV1> {
self.get_payload_bodies_by_range_with(start, count, convert_to_payload_body_v1).await
self.get_payload_bodies_by_range_with(start, count, |block| {
let transactions =
block.body().transactions().iter().map(|tx| tx.encoded_2718().into());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a helper fn for this:

fn encoded_2718_transactions(&self) -> Vec<Bytes> {

ExecutionPayloadBodyV1 {
transactions: transactions.collect(),
withdrawals: block.body().withdrawals().cloned().map(Withdrawals::into_inner),
}
})
.await
}

/// Called to retrieve execution payload bodies by hashes.
Expand Down Expand Up @@ -597,7 +607,15 @@ where
&self,
hashes: Vec<BlockHash>,
) -> EngineApiResult<ExecutionPayloadBodiesV1> {
self.get_payload_bodies_by_hash_with(hashes, convert_to_payload_body_v1).await
self.get_payload_bodies_by_hash_with(hashes, |block| {
let transactions =
block.body().transactions().iter().map(|tx| tx.encoded_2718().into());
ExecutionPayloadBodyV1 {
transactions: transactions.collect(),
withdrawals: block.body().withdrawals().cloned().map(Withdrawals::into_inner),
}
})
.await
}

/// Called to verify network configuration parameters and ensure that Consensus and Execution
Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc-types-compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ reth-primitives.workspace = true
reth-primitives-traits.workspace = true

# ethereum
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types-eth = { workspace = true, default-features = false, features = ["serde"] }
alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true

# io
Expand Down
15 changes: 0 additions & 15 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can now delete the entire engine module

Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
//! Standalone Conversion Functions for Handling Different Versions of Execution Payloads in
//! Ethereum's Engine

use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
use alloy_rpc_types_engine::payload::ExecutionPayloadBodyV1;
use reth_primitives_traits::BlockBody as _;

/// Converts a [`reth_primitives_traits::Block`] to [`ExecutionPayloadBodyV1`]
pub fn convert_to_payload_body_v1(
value: impl reth_primitives_traits::Block,
) -> ExecutionPayloadBodyV1 {
let transactions = value.body().transactions_iter().map(|tx| tx.encoded_2718().into());
ExecutionPayloadBodyV1 {
transactions: transactions.collect(),
withdrawals: value.body().withdrawals().cloned().map(Withdrawals::into_inner),
}
}

#[cfg(test)]
mod tests {
use alloy_primitives::{b256, hex, Bytes, U256};
Expand Down
Loading