Skip to content

Commit

Permalink
chore: remove block_to_payload_v1 (#14143)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
temaniarpit27 and mattsse authored Feb 1, 2025
1 parent 5c7df17 commit 209b448
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 47 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2904,7 +2904,7 @@ mod tests {
use alloy_primitives::Bytes;
use alloy_rlp::Decodable;
use alloy_rpc_types_engine::{
CancunPayloadFields, ExecutionPayloadSidecar, ExecutionPayloadV3,
CancunPayloadFields, ExecutionPayloadSidecar, ExecutionPayloadV1, ExecutionPayloadV3,
};
use assert_matches::assert_matches;
use reth_chain_state::{test_utils::TestBlockBuilder, BlockState};
Expand All @@ -2916,7 +2916,6 @@ mod tests {
use reth_evm::test_utils::MockExecutorProvider;
use reth_primitives_traits::Block as _;
use reth_provider::test_utils::MockEthProvider;
use reth_rpc_types_compat::engine::block_to_payload_v1;
use reth_trie::{updates::TrieUpdates, HashedPostState};
use std::{
str::FromStr,
Expand Down Expand Up @@ -3455,7 +3454,7 @@ mod tests {
let block = Block::decode(&mut data.as_ref()).unwrap();
let sealed = block.seal_slow();
let hash = sealed.hash();
let payload = block_to_payload_v1(sealed.clone());
let payload = ExecutionPayloadV1::from_block_unchecked(hash, &sealed.clone().into_block());

let mut test_harness = TestHarness::new(HOLESKY.clone());

Expand Down Expand Up @@ -3495,7 +3494,8 @@ mod tests {
let data = Bytes::from_str(s).unwrap();
let block: Block = Block::decode(&mut data.as_ref()).unwrap();
let sealed = block.seal_slow();
let payload = block_to_payload_v1(sealed);
let payload =
ExecutionPayloadV1::from_block_unchecked(sealed.hash(), &sealed.clone().into_block());

let mut test_harness =
TestHarness::new(HOLESKY.clone()).with_backfill_state(BackfillSyncState::Active);
Expand Down
1 change: 0 additions & 1 deletion crates/engine/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ reth-errors.workspace = true
reth-chainspec.workspace = true
reth-consensus-common.workspace = true
reth-fs-util.workspace = true
reth-rpc-types-compat.workspace = true
reth-engine-primitives.workspace = true
reth-payload-validator.workspace = true
reth-evm.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/ethereum/engine-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ reth-primitives.workspace = true
reth-engine-primitives.workspace = true
reth-payload-primitives.workspace = true
reth-payload-validator.workspace = true
reth-rpc-types-compat.workspace = true

# alloy
alloy-primitives.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions crates/ethereum/engine-primitives/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use alloy_rpc_types_engine::{
use core::convert::Infallible;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_primitives::{EthPrimitives, SealedBlock};
use reth_rpc_types_compat::engine::payload::block_to_payload_v1;

/// Contains the built payload.
///
Expand Down Expand Up @@ -118,7 +117,10 @@ impl BuiltPayload for &EthBuiltPayload {
// V1 engine_getPayloadV1 response
impl From<EthBuiltPayload> for ExecutionPayloadV1 {
fn from(value: EthBuiltPayload) -> Self {
block_to_payload_v1(Arc::unwrap_or_clone(value.block))
Self::from_block_unchecked(
value.block().hash(),
&Arc::unwrap_or_clone(value.block).into_block(),
)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/optimism/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ reth-primitives-traits.workspace = true
reth-revm = { workspace = true, features = ["witness"] }
reth-transaction-pool.workspace = true
reth-provider.workspace = true
reth-rpc-types-compat.workspace = true
reth-evm.workspace = true
reth-execution-types.workspace = true
reth-payload-builder.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use reth_optimism_primitives::{OpBlock, OpPrimitives, OpTransactionSigned};
use reth_payload_builder::EthPayloadBuilderAttributes;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_primitives::{transaction::WithEncoded, SealedBlock};
use reth_rpc_types_compat::engine::payload::block_to_payload_v1;

use std::sync::Arc;

/// Optimism Payload Builder Attributes
Expand Down Expand Up @@ -229,7 +229,10 @@ impl BuiltPayload for &OpBuiltPayload {
// V1 engine_getPayloadV1 response
impl From<OpBuiltPayload> for ExecutionPayloadV1 {
fn from(value: OpBuiltPayload) -> Self {
block_to_payload_v1(Arc::unwrap_or_clone(value.block))
Self::from_block_unchecked(
value.block().hash(),
&Arc::unwrap_or_clone(value.block).into_block(),
)
}
}

Expand Down
7 changes: 5 additions & 2 deletions crates/rpc/rpc-builder/tests/it/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ use reth_primitives::{Block, TransactionSigned};
use reth_primitives_traits::block::Block as _;
use reth_rpc_api::clients::EngineApiClient;
use reth_rpc_layer::JwtSecret;
use reth_rpc_types_compat::engine::payload::block_to_payload_v1;

#[allow(unused_must_use)]
async fn test_basic_engine_calls<C>(client: &C)
where
C: ClientT + SubscriptionClientT + Sync + EngineApiClient<EthEngineTypes>,
{
let block = Block::<_>::default().seal_slow();
EngineApiClient::new_payload_v1(client, block_to_payload_v1(block.clone())).await;
EngineApiClient::new_payload_v1(
client,
ExecutionPayloadV1::from_block_unchecked(block.hash(), &block.clone().into_block()),
)
.await;
EngineApiClient::new_payload_v2(
client,
ExecutionPayloadInputV2 {
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use alloy_rpc_types_engine::{
use assert_matches::assert_matches;
use reth_primitives::{Block, SealedBlock, TransactionSigned};
use reth_primitives_traits::proofs;
use reth_rpc_types_compat::engine::payload::block_to_payload_v1;
use reth_testing_utils::generators::{
self, random_block, random_block_range, BlockParams, BlockRangeParams, Rng,
};
Expand Down Expand Up @@ -99,7 +98,8 @@ fn payload_validation_conversion() {
);

// Invalid encoded transactions
let mut payload_with_invalid_txs: ExecutionPayloadV1 = block_to_payload_v1(block);
let mut payload_with_invalid_txs =
ExecutionPayloadV1::from_block_unchecked(block.hash(), &block.into_block());

payload_with_invalid_txs.transactions.iter_mut().for_each(|tx| {
*tx = Bytes::new();
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/rpc-types-compat/src/engine/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
//! Standalone functions for engine specific rpc type conversions
pub mod payload;
pub use payload::block_to_payload_v1;
30 changes: 2 additions & 28 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,8 @@
//! Ethereum's Engine
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
use alloy_primitives::U256;
use alloy_rpc_types_engine::{payload::ExecutionPayloadBodyV1, ExecutionPayloadV1};
use reth_primitives::{Block, SealedBlock};
use reth_primitives_traits::{BlockBody as _, SignedTransaction};

/// Converts [`SealedBlock`] to [`ExecutionPayloadV1`]
pub fn block_to_payload_v1<T: SignedTransaction>(
value: SealedBlock<Block<T>>,
) -> ExecutionPayloadV1 {
let transactions =
value.body().transactions.iter().map(|tx| tx.encoded_2718().into()).collect::<Vec<_>>();
ExecutionPayloadV1 {
parent_hash: value.parent_hash,
fee_recipient: value.beneficiary,
state_root: value.state_root,
receipts_root: value.receipts_root,
logs_bloom: value.logs_bloom,
prev_randao: value.mix_hash,
block_number: value.number,
gas_limit: value.gas_limit,
gas_used: value.gas_used,
timestamp: value.timestamp,
extra_data: value.extra_data.clone(),
base_fee_per_gas: U256::from(value.base_fee_per_gas.unwrap_or_default()),
block_hash: value.hash(),
transactions,
}
}
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(
Expand Down

0 comments on commit 209b448

Please sign in to comment.