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

feat: phase out payload conversion helpers #14090

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions bin/reth-bench/src/bench/new_payload_fcu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ use crate::{
};
use alloy_primitives::B256;
use alloy_provider::{network::AnyRpcBlock, Provider};
use alloy_rpc_types_engine::ForkchoiceState;
use alloy_rpc_types_engine::{ExecutionPayload, ForkchoiceState};
use clap::Parser;
use csv::Writer;
use reth_cli_runner::CliContext;
use reth_node_core::args::BenchmarkArgs;
use reth_primitives::SealedBlock;
use reth_primitives_traits::SealedHeader;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::time::Instant;
use tracing::{debug, info};

Expand Down Expand Up @@ -81,7 +80,8 @@ impl Command {
let versioned_hashes: Vec<B256> =
block.body().blob_versioned_hashes_iter().copied().collect();
let parent_beacon_block_root = block.parent_beacon_block_root;
let payload = block_to_payload(block).0;
let (payload, _) =
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block());

debug!(?block_number, "Sending payload",);

Expand Down
5 changes: 3 additions & 2 deletions bin/reth-bench/src/bench/new_payload_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use crate::{
};
use alloy_primitives::B256;
use alloy_provider::Provider;
use alloy_rpc_types_engine::ExecutionPayload;
use clap::Parser;
use csv::Writer;
use reth_cli_runner::CliContext;
use reth_node_core::args::BenchmarkArgs;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::time::Instant;
use tracing::{debug, info};

Expand Down Expand Up @@ -64,7 +64,8 @@ impl Command {
let versioned_hashes: Vec<B256> =
block.body().blob_versioned_hashes_iter().copied().collect();
let parent_beacon_block_root = block.parent_beacon_block_root;
let payload = block_to_payload(block).0;
let (payload, _) =
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block());

let block_number = payload.block_number();

Expand Down
3 changes: 1 addition & 2 deletions crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use reth_revm::{
db::{states::bundle_state::BundleRetention, State},
DatabaseCommit,
};
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::{
collections::VecDeque,
future::Future,
Expand Down Expand Up @@ -426,7 +425,7 @@ where
.seal_slow();

Ok((
block_to_payload(reorg_block).0,
ExecutionPayload::from_block_unchecked(reorg_block.hash(), &reorg_block.into_block()).0,
// todo(onbjerg): how do we support execution requests?
reorg_target
.header
Expand Down
3 changes: 1 addition & 2 deletions crates/ethereum/engine-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use reth_payload_primitives::{
};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{Block, NodePrimitives, SealedBlock};
use reth_rpc_types_compat::engine::payload::block_to_payload;

/// The types used in the default mainnet ethereum beacon consensus engine.
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -61,7 +60,7 @@ where
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
block_to_payload(block)
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block())
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/optimism/node/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use reth_optimism_payload_builder::{OpBuiltPayload, OpPayloadBuilderAttributes};
use reth_optimism_primitives::OpBlock;
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::SealedBlock;
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::sync::Arc;

/// The types used in the optimism beacon consensus engine.
Expand Down Expand Up @@ -55,7 +54,7 @@ where
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
block_to_payload(block)
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block())
}
}

Expand Down
11 changes: 4 additions & 7 deletions crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use alloy_rpc_types_engine::{
PayloadError,
};
use assert_matches::assert_matches;
use reth_primitives::{Block, SealedBlock, SealedHeader, TransactionSigned};
use reth_primitives::{Block, SealedBlock, TransactionSigned};
use reth_primitives_traits::proofs;
use reth_rpc_types_compat::engine::payload::{block_to_payload, block_to_payload_v1};
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 All @@ -22,11 +22,8 @@ fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> Executi
transformed.header.transactions_root =
proofs::calculate_transaction_root(&transformed.body.transactions);
transformed.header.ommers_hash = proofs::calculate_ommers_root(&transformed.body.ommers);
block_to_payload(SealedBlock::from_sealed_parts(
SealedHeader::seal_slow(transformed.header),
transformed.body,
))
.0

ExecutionPayload::from_block_slow(&transformed).0
}

#[test]
Expand Down
41 changes: 2 additions & 39 deletions crates/rpc/rpc-types-compat/src/engine/payload.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,15 @@
//! Standalone Conversion Functions for Handling Different Versions of Execution Payloads in
//! Ethereum's Engine

use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals, eip7685::RequestsOrHash};
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
use alloy_primitives::U256;
use alloy_rpc_types_engine::{
payload::{ExecutionPayloadBodyV1, ExecutionPayloadFieldV2},
CancunPayloadFields, ExecutionPayload, ExecutionPayloadSidecar, ExecutionPayloadV1,
ExecutionPayloadV2, ExecutionPayloadV3, PraguePayloadFields,
ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3,
};
use reth_primitives::{Block, SealedBlock};
use reth_primitives_traits::{BlockBody as _, SignedTransaction};

/// Converts [`SealedBlock`] to [`ExecutionPayload`].
///
/// TODO(mattsse): remove after next alloy bump
pub fn block_to_payload<T: SignedTransaction>(
value: SealedBlock<Block<T>>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
let cancun =
value.parent_beacon_block_root.map(|parent_beacon_block_root| CancunPayloadFields {
parent_beacon_block_root,
versioned_hashes: value.body().blob_versioned_hashes_iter().copied().collect(),
});

let prague = value
.requests_hash
.map(|requests_hash| PraguePayloadFields { requests: RequestsOrHash::Hash(requests_hash) });

let sidecar = match (cancun, prague) {
(Some(cancun), Some(prague)) => ExecutionPayloadSidecar::v4(cancun, prague),
(Some(cancun), None) => ExecutionPayloadSidecar::v3(cancun),
_ => ExecutionPayloadSidecar::none(),
};

let execution_payload = if value.parent_beacon_block_root.is_some() {
// block with parent beacon block root: V3
ExecutionPayload::V3(block_to_payload_v3(value))
} else if value.body().withdrawals.is_some() {
// block with withdrawals: V2
ExecutionPayload::V2(block_to_payload_v2(value))
} else {
// otherwise V1
ExecutionPayload::V1(block_to_payload_v1(value))
};

(execution_payload, sidecar)
}

/// Converts [`SealedBlock`] to [`ExecutionPayloadV1`]
pub fn block_to_payload_v1<T: SignedTransaction>(
value: SealedBlock<Block<T>>,
Expand Down
3 changes: 1 addition & 2 deletions examples/custom-engine-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use reth::{
primitives::{Block, EthPrimitives, SealedBlock, TransactionSigned},
providers::{CanonStateSubscriptions, EthStorage, StateProviderFactory},
rpc::{
compat::engine::payload::block_to_payload,
eth::EthApi,
types::engine::{ExecutionPayload, ExecutionPayloadSidecar, PayloadError},
},
Expand Down Expand Up @@ -181,7 +180,7 @@ impl EngineTypes for CustomEngineTypes {
<<Self::BuiltPayload as reth_node_api::BuiltPayload>::Primitives as reth_node_api::NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
block_to_payload(block)
ExecutionPayload::from_block_unchecked(block.hash(), &block.into_block())
}
}

Expand Down
Loading