refactor: integrate BuiltPayload::Primitives (#13484)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Arsenii Kulikov
2024-12-24 03:06:47 +04:00
committed by GitHub
parent 4c1208e9d9
commit af1c9b7614
24 changed files with 136 additions and 78 deletions

3
Cargo.lock generated
View File

@ -7328,7 +7328,6 @@ dependencies = [
"reth-payload-primitives",
"reth-provider",
"reth-prune",
"reth-rpc-types-compat",
"reth-stages-api",
"reth-transaction-pool",
"tokio",
@ -8540,6 +8539,7 @@ dependencies = [
"reth-provider",
"reth-revm",
"reth-rpc-server-types",
"reth-rpc-types-compat",
"reth-tasks",
"reth-tracing",
"reth-transaction-pool",
@ -8571,6 +8571,7 @@ dependencies = [
"reth-optimism-consensus",
"reth-optimism-evm",
"reth-optimism-forks",
"reth-optimism-primitives",
"reth-payload-builder",
"reth-payload-builder-primitives",
"reth-payload-primitives",

View File

@ -81,7 +81,7 @@ 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);
let payload = block_to_payload(block).0;
debug!(?block_number, "Sending payload",);

View File

@ -65,7 +65,7 @@ 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);
let payload = block_to_payload(block).0;
let block_number = payload.block_number();

View File

@ -107,7 +107,7 @@ where
let tx_hash = self.rpc.inject_tx(raw_tx).await?;
let (payload, eth_attr) = self.advance_block().await?;
let block_hash = payload.block().hash();
let block_number = payload.block().number;
let block_number = payload.block().number();
self.assert_new_block(tx_hash, block_hash, block_number).await?;
chain.push((payload, eth_attr));
}

View File

@ -1,4 +1,5 @@
use futures_util::StreamExt;
use reth_node_api::BlockBody;
use reth_payload_builder::{PayloadBuilderHandle, PayloadId};
use reth_payload_builder_primitives::{Events, PayloadBuilder};
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadTypes};
@ -57,7 +58,7 @@ impl<T: PayloadTypes> PayloadTestContext<T> {
pub async fn wait_for_built_payload(&self, payload_id: PayloadId) {
loop {
let payload = self.payload_builder.best_payload(payload_id).await.unwrap().unwrap();
if payload.block().body.transactions.is_empty() {
if payload.block().body.transactions().is_empty() {
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
continue
}

View File

@ -24,7 +24,6 @@ reth-payload-builder-primitives.workspace = true
reth-payload-primitives.workspace = true
reth-provider.workspace = true
reth-prune.workspace = true
reth-rpc-types-compat.workspace = true
reth-transaction-pool.workspace = true
reth-stages-api.workspace = true

View File

@ -2,16 +2,14 @@
use alloy_consensus::BlockHeader;
use alloy_primitives::{TxHash, B256};
use alloy_rpc_types_engine::{CancunPayloadFields, ExecutionPayloadSidecar, ForkchoiceState};
use alloy_rpc_types_engine::ForkchoiceState;
use eyre::OptionExt;
use futures_util::{stream::Fuse, StreamExt};
use reth_chainspec::EthereumHardforks;
use reth_engine_primitives::{BeaconEngineMessage, EngineApiMessageVersion, EngineTypes};
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_builder_primitives::PayloadBuilder;
use reth_payload_primitives::{BuiltPayload, PayloadAttributesBuilder, PayloadKind, PayloadTypes};
use reth_provider::{BlockReader, ChainSpecProvider};
use reth_rpc_types_compat::engine::payload::block_to_payload;
use reth_provider::BlockReader;
use reth_transaction_pool::TransactionPool;
use std::{
future::Future,
@ -75,9 +73,7 @@ impl Future for MiningMode {
/// Local miner advancing the chain/
#[derive(Debug)]
pub struct LocalMiner<EngineT: EngineTypes, Provider, B> {
/// Provider to read the current tip of the chain.
provider: Provider,
pub struct LocalMiner<EngineT: EngineTypes, B> {
/// The payload attribute builder for the engine
payload_attributes_builder: B,
/// Sender for events to engine.
@ -92,15 +88,14 @@ pub struct LocalMiner<EngineT: EngineTypes, Provider, B> {
last_block_hashes: Vec<B256>,
}
impl<EngineT, Provider, B> LocalMiner<EngineT, Provider, B>
impl<EngineT, B> LocalMiner<EngineT, B>
where
EngineT: EngineTypes,
Provider: BlockReader + ChainSpecProvider<ChainSpec: EthereumHardforks> + 'static,
B: PayloadAttributesBuilder<<EngineT as PayloadTypes>::PayloadAttributes>,
{
/// Spawns a new [`LocalMiner`] with the given parameters.
pub fn spawn_new(
provider: Provider,
provider: impl BlockReader,
payload_attributes_builder: B,
to_engine: UnboundedSender<BeaconEngineMessage<EngineT>>,
mode: MiningMode,
@ -110,7 +105,6 @@ where
provider.sealed_header(provider.best_block_number().unwrap()).unwrap().unwrap();
let miner = Self {
provider,
payload_attributes_builder,
to_engine,
mode,
@ -211,21 +205,12 @@ where
let block = payload.block();
let cancun_fields =
self.provider.chain_spec().is_cancun_active_at_timestamp(block.timestamp).then(|| {
CancunPayloadFields {
parent_beacon_block_root: block.parent_beacon_block_root.unwrap(),
versioned_hashes: block.body.blob_versioned_hashes_iter().copied().collect(),
}
});
let (tx, rx) = oneshot::channel();
let (payload, sidecar) = EngineT::block_to_payload(payload.block().clone());
self.to_engine.send(BeaconEngineMessage::NewPayload {
payload: block_to_payload(payload.block().clone()),
payload,
// todo: prague support
sidecar: cancun_fields
.map(ExecutionPayloadSidecar::v3)
.unwrap_or_else(ExecutionPayloadSidecar::none),
sidecar,
tx,
})?;

View File

@ -30,7 +30,7 @@ pub use reth_payload_primitives::{
PayloadTypes,
};
use reth_payload_primitives::{InvalidPayloadAttributesError, PayloadAttributes};
use reth_primitives::SealedBlockFor;
use reth_primitives::{NodePrimitives, SealedBlockFor};
use reth_primitives_traits::Block;
use serde::{de::DeserializeOwned, ser::Serialize};
@ -80,6 +80,13 @@ pub trait EngineTypes:
+ Send
+ Sync
+ 'static;
/// Converts a [`BuiltPayload`] into an [`ExecutionPayload`] and [`ExecutionPayloadSidecar`].
fn block_to_payload(
block: SealedBlockFor<
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar);
}
/// Type that validates an [`ExecutionPayload`].

View File

@ -437,7 +437,7 @@ where
.seal_slow();
Ok((
block_to_payload(reorg_block),
block_to_payload(reorg_block).0,
// todo(onbjerg): how do we support execution requests?
reorg_target
.header

View File

@ -18,13 +18,14 @@ pub use alloy_rpc_types_engine::{
};
pub use payload::{EthBuiltPayload, EthPayloadBuilderAttributes};
use reth_chainspec::ChainSpec;
use reth_engine_primitives::{EngineTypes, EngineValidator, PayloadValidator};
use reth_engine_primitives::{BuiltPayload, EngineTypes, EngineValidator, PayloadValidator};
use reth_payload_primitives::{
validate_version_specific_fields, EngineApiMessageVersion, EngineObjectValidationError,
PayloadOrAttributes, PayloadTypes,
};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{Block, SealedBlock};
use reth_primitives::{Block, NodePrimitives, SealedBlock, SealedBlockFor};
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)]
@ -39,9 +40,11 @@ impl<T: PayloadTypes> PayloadTypes for EthEngineTypes<T> {
type PayloadBuilderAttributes = T::PayloadBuilderAttributes;
}
impl<T: PayloadTypes> EngineTypes for EthEngineTypes<T>
impl<T> EngineTypes for EthEngineTypes<T>
where
T::BuiltPayload: TryInto<ExecutionPayloadV1>
T: PayloadTypes,
T::BuiltPayload: BuiltPayload<Primitives: NodePrimitives<Block = reth_primitives::Block>>
+ TryInto<ExecutionPayloadV1>
+ TryInto<ExecutionPayloadEnvelopeV2>
+ TryInto<ExecutionPayloadEnvelopeV3>
+ TryInto<ExecutionPayloadEnvelopeV4>,
@ -50,6 +53,14 @@ where
type ExecutionPayloadEnvelopeV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadEnvelopeV3 = ExecutionPayloadEnvelopeV3;
type ExecutionPayloadEnvelopeV4 = ExecutionPayloadEnvelopeV4;
fn block_to_payload(
block: SealedBlockFor<
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
block_to_payload(block)
}
}
/// A default payload type for [`EthEngineTypes`]

View File

@ -9,7 +9,7 @@ use alloy_rpc_types_engine::{
};
use reth_chain_state::ExecutedBlock;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_primitives::SealedBlock;
use reth_primitives::{EthPrimitives, SealedBlock};
use reth_rpc_types_compat::engine::payload::{
block_to_payload_v1, block_to_payload_v3, convert_block_to_payload_field_v2,
};
@ -89,6 +89,8 @@ impl EthBuiltPayload {
}
impl BuiltPayload for EthBuiltPayload {
type Primitives = EthPrimitives;
fn block(&self) -> &SealedBlock {
&self.block
}
@ -107,6 +109,8 @@ impl BuiltPayload for EthBuiltPayload {
}
impl BuiltPayload for &EthBuiltPayload {
type Primitives = EthPrimitives;
fn block(&self) -> &SealedBlock {
(**self).block()
}
@ -166,24 +170,9 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV3 {
impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV4 {
fn from(value: EthBuiltPayload) -> Self {
let EthBuiltPayload { block, fees, sidecars, requests, .. } = value;
Self {
envelope_inner: ExecutionPayloadEnvelopeV3 {
execution_payload: block_to_payload_v3(Arc::unwrap_or_clone(block)),
block_value: fees,
// From the engine API spec:
//
// > Client software **MAY** use any heuristics to decide whether to set
// `shouldOverrideBuilder` flag or not. If client software does not implement any
// heuristic this flag **SHOULD** be set to `false`.
//
// Spec:
// <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#specification-2>
should_override_builder: false,
blobs_bundle: sidecars.into_iter().map(Into::into).collect::<Vec<_>>().into(),
},
execution_requests: requests.unwrap_or_default(),
execution_requests: value.requests.clone().unwrap_or_default(),
envelope_inner: value.into(),
}
}
}

View File

@ -19,7 +19,7 @@ use reth_db_api::{
database_metrics::{DatabaseMetadata, DatabaseMetrics},
Database,
};
use reth_engine_primitives::EngineTypes;
use reth_engine_primitives::{BuiltPayload, EngineTypes};
use reth_trie_db::StateCommitment;
/// The type that configures the essential types of an Ethereum-like node.
@ -41,7 +41,7 @@ pub trait NodeTypes: Send + Sync + Unpin + 'static {
/// The type that configures an Ethereum-like node with an engine for consensus.
pub trait NodeTypesWithEngine: NodeTypes {
/// The node's engine types, defining the interaction with the consensus engine.
type Engine: EngineTypes;
type Engine: EngineTypes<BuiltPayload: BuiltPayload<Primitives = Self::Primitives>>;
}
/// A helper trait that is downstream of the [`NodeTypesWithEngine`] trait and adds database to the
@ -225,7 +225,7 @@ where
impl<P, E, C, SC, S> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C, SC, S>
where
P: NodePrimitives + Send + Sync + Unpin + 'static,
E: EngineTypes + Send + Sync + Unpin,
E: EngineTypes<BuiltPayload: BuiltPayload<Primitives = P>> + Send + Sync + Unpin,
C: EthChainSpec<Header = P::BlockHeader> + 'static,
SC: StateCommitment,
S: Default + Send + Sync + Unpin + Debug + 'static,

View File

@ -33,6 +33,7 @@ reth-revm = { workspace = true, features = ["std"] }
reth-beacon-consensus.workspace = true
reth-trie-db.workspace = true
reth-rpc-server-types.workspace = true
reth-rpc-types-compat.workspace = true
reth-tasks = { workspace = true, optional = true }
# op-reth

View File

@ -12,13 +12,15 @@ use reth_node_api::{
EngineObjectValidationError, MessageValidationKind, PayloadOrAttributes, PayloadTypes,
VersionSpecificValidationError,
},
validate_version_specific_fields, EngineTypes, EngineValidator, PayloadValidator,
validate_version_specific_fields, BuiltPayload, EngineTypes, EngineValidator, NodePrimitives,
PayloadValidator,
};
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_forks::{OpHardfork, OpHardforks};
use reth_optimism_payload_builder::{OpBuiltPayload, OpPayloadBuilderAttributes};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{Block, SealedBlockFor};
use reth_rpc_types_compat::engine::payload::block_to_payload;
use std::sync::Arc;
/// The types used in the optimism beacon consensus engine.
@ -36,7 +38,8 @@ impl<T: PayloadTypes> PayloadTypes for OpEngineTypes<T> {
impl<T: PayloadTypes> EngineTypes for OpEngineTypes<T>
where
T::BuiltPayload: TryInto<ExecutionPayloadV1>
T::BuiltPayload: BuiltPayload<Primitives: NodePrimitives<Block = reth_primitives::Block>>
+ TryInto<ExecutionPayloadV1>
+ TryInto<ExecutionPayloadEnvelopeV2>
+ TryInto<OpExecutionPayloadEnvelopeV3>
+ TryInto<OpExecutionPayloadEnvelopeV4>,
@ -45,6 +48,14 @@ where
type ExecutionPayloadEnvelopeV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadEnvelopeV3 = OpExecutionPayloadEnvelopeV3;
type ExecutionPayloadEnvelopeV4 = OpExecutionPayloadEnvelopeV4;
fn block_to_payload(
block: SealedBlockFor<
<<Self::BuiltPayload as BuiltPayload>::Primitives as NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
block_to_payload(block)
}
}
/// A default payload type for [`OpEngineTypes`]

View File

@ -33,6 +33,7 @@ reth-optimism-chainspec.workspace = true
reth-optimism-consensus.workspace = true
reth-optimism-evm.workspace = true
reth-optimism-forks.workspace = true
reth-optimism-primitives.workspace = true
# ethereum
revm.workspace = true
@ -57,5 +58,6 @@ optimism = [
"reth-optimism-evm/optimism",
"revm/optimism",
"reth-execution-types/optimism",
"reth-optimism-consensus/optimism"
]
"reth-optimism-consensus/optimism",
"reth-optimism-primitives/optimism"
]

View File

@ -14,6 +14,7 @@ use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpExecutionPayload
use reth_chain_state::ExecutedBlock;
use reth_chainspec::EthereumHardforks;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::OpPrimitives;
use reth_payload_builder::EthPayloadBuilderAttributes;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_primitives::{transaction::WithEncoded, SealedBlock, TransactionSigned};
@ -186,6 +187,8 @@ impl OpBuiltPayload {
}
impl BuiltPayload for OpBuiltPayload {
type Primitives = OpPrimitives;
fn block(&self) -> &SealedBlock {
&self.block
}
@ -204,6 +207,8 @@ impl BuiltPayload for OpBuiltPayload {
}
impl BuiltPayload for &OpBuiltPayload {
type Primitives = OpPrimitives;
fn block(&self) -> &SealedBlock {
(**self).block()
}

View File

@ -7,7 +7,7 @@ use alloy_eips::eip4895::Withdrawals;
use alloy_primitives::{Address, B256, U256};
use reth_payload_builder::PayloadId;
use reth_payload_primitives::BuiltPayload;
use reth_primitives::SealedBlock;
use reth_primitives::{NodePrimitives, SealedBlockFor};
use alloy_eips::eip7685::Requests;
use std::{error::Error, fmt};
@ -151,9 +151,11 @@ where
impl<L, R> BuiltPayload for Either<L, R>
where
L: BuiltPayload,
R: BuiltPayload,
R: BuiltPayload<Primitives = L::Primitives>,
{
fn block(&self) -> &SealedBlock {
type Primitives = L::Primitives;
fn block(&self) -> &SealedBlockFor<<L::Primitives as NodePrimitives>::Block> {
match self {
Self::Left(l) => l.block(),
Self::Right(r) => r.block(),
@ -184,7 +186,8 @@ where
L::Attributes: Unpin + Clone,
R::Attributes: Unpin + Clone,
L::BuiltPayload: Unpin + Clone,
R::BuiltPayload: Unpin + Clone,
R::BuiltPayload:
BuiltPayload<Primitives = <L::BuiltPayload as BuiltPayload>::Primitives> + Unpin + Clone,
<<L as PayloadBuilder<Pool, Client>>::Attributes as PayloadBuilderAttributes>::Error: 'static,
<<R as PayloadBuilder<Pool, Client>>::Attributes as PayloadBuilderAttributes>::Error: 'static,
{

View File

@ -21,6 +21,7 @@ reth-payload-primitives.workspace = true
reth-ethereum-engine-primitives.workspace = true
# alloy
alloy-consensus.workspace = true
alloy-primitives = { workspace = true, optional = true }
alloy-rpc-types = { workspace = true, features = ["engine"] }

View File

@ -7,6 +7,7 @@ use crate::{
metrics::PayloadBuilderServiceMetrics, traits::PayloadJobGenerator, KeepPayloadJobAlive,
PayloadJob,
};
use alloy_consensus::BlockHeader;
use alloy_rpc_types::engine::PayloadId;
use futures_util::{future::FutureExt, Stream, StreamExt};
use reth_chain_state::CanonStateNotification;
@ -284,7 +285,7 @@ where
.find(|(_, job_id)| *job_id == id)
.map(|(j, _)| j.best_payload().map(|p| p.into()));
if let Some(Ok(ref best)) = res {
self.metrics.set_best_revenue(best.block().number, f64::from(best.fees()));
self.metrics.set_best_revenue(best.block().number(), f64::from(best.fees()));
}
res
@ -318,7 +319,7 @@ where
payload_events.send(Events::BuiltPayload(payload.clone().into())).ok();
resolved_metrics
.set_resolved_revenue(payload.block().number, f64::from(payload.fees()));
.set_resolved_revenue(payload.block().number(), f64::from(payload.fees()));
}
res.map(|p| p.into())
};

View File

@ -5,19 +5,22 @@ use alloy_eips::{
use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types_engine::{PayloadAttributes as EthPayloadAttributes, PayloadId};
use reth_chain_state::ExecutedBlock;
use reth_primitives::{EthPrimitives, NodePrimitives, SealedBlock};
use reth_primitives::{NodePrimitives, SealedBlockFor};
/// Represents a built payload type that contains a built [`SealedBlock`] and can be converted into
/// Represents a built payload type that contains a built `SealedBlock` and can be converted into
/// engine API execution payloads.
pub trait BuiltPayload<N: NodePrimitives = EthPrimitives>: Send + Sync + std::fmt::Debug {
pub trait BuiltPayload: Send + Sync + std::fmt::Debug {
/// The node's primitive types
type Primitives: NodePrimitives;
/// Returns the built block (sealed)
fn block(&self) -> &SealedBlock<N::BlockHeader, N::BlockBody>;
fn block(&self) -> &SealedBlockFor<<Self::Primitives as NodePrimitives>::Block>;
/// Returns the fees collected for the built block
fn fees(&self) -> U256;
/// Returns the entire execution data for the built block, if available.
fn executed_block(&self) -> Option<ExecutedBlock<N>> {
fn executed_block(&self) -> Option<ExecutedBlock<Self::Primitives>> {
None
}

View File

@ -467,6 +467,7 @@ pub type SealedBlockFor<B> = SealedBlock<
<B as reth_primitives_traits::Block>::Header,
<B as reth_primitives_traits::Block>::Body,
>;
/// Sealed block with senders recovered from transactions.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Deref, DerefMut)]
pub struct SealedBlockWithSenders<B: reth_primitives_traits::Block = Block> {

View File

@ -28,6 +28,7 @@ fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> Executi
header: SealedHeader::seal(transformed.header),
body: transformed.body,
})
.0
}
#[test]

View File

@ -5,19 +5,20 @@ use alloy_consensus::{constants::MAXIMUM_EXTRA_DATA_SIZE, Header, EMPTY_OMMER_RO
use alloy_eips::{
eip2718::{Decodable2718, Encodable2718},
eip4895::Withdrawals,
eip7685::RequestsOrHash,
};
use alloy_primitives::{B256, U256};
use alloy_rlp::BufMut;
use alloy_rpc_types_engine::{
payload::{ExecutionPayloadBodyV1, ExecutionPayloadFieldV2, ExecutionPayloadInputV2},
ExecutionPayload, ExecutionPayloadSidecar, ExecutionPayloadV1, ExecutionPayloadV2,
ExecutionPayloadV3, PayloadError,
CancunPayloadFields, ExecutionPayload, ExecutionPayloadSidecar, ExecutionPayloadV1,
ExecutionPayloadV2, ExecutionPayloadV3, PayloadError, PraguePayloadFields,
};
use reth_primitives::{
proofs::{self},
Block, BlockBody, BlockExt, SealedBlock,
};
use reth_primitives_traits::BlockBody as _;
use reth_primitives_traits::{BlockBody as _, SignedTransaction};
/// Converts [`ExecutionPayloadV1`] to [`Block`]
pub fn try_payload_v1_to_block<T: Decodable2718>(
@ -119,10 +120,34 @@ pub fn try_payload_v3_to_block<T: Decodable2718>(
}
/// Converts [`SealedBlock`] to [`ExecutionPayload`]
pub fn block_to_payload<T: Encodable2718>(
pub fn block_to_payload<T: SignedTransaction>(
value: SealedBlock<Header, BlockBody<T>>,
) -> ExecutionPayload {
if value.header.parent_beacon_block_root.is_some() {
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
let cancun = if let Some(parent_beacon_block_root) = value.parent_beacon_block_root {
Some(CancunPayloadFields {
parent_beacon_block_root,
versioned_hashes: value.body.blob_versioned_hashes_iter().copied().collect(),
})
} else {
None
};
let prague = if let Some(requests_hash) = value.requests_hash {
Some(PraguePayloadFields {
requests: RequestsOrHash::Hash(requests_hash),
target_blobs_per_block: value.target_blobs_per_block.unwrap_or_default(),
})
} else {
None
};
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.header.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() {
@ -131,7 +156,9 @@ pub fn block_to_payload<T: Encodable2718>(
} else {
// otherwise V1
ExecutionPayload::V1(block_to_payload_v1(value))
}
};
(execution_payload, sidecar)
}
/// Converts [`SealedBlock`] to [`ExecutionPayloadV1`]

View File

@ -41,6 +41,7 @@ use reth::{
primitives::{Block, EthPrimitives, SealedBlockFor, TransactionSigned},
providers::{CanonStateSubscriptions, EthStorage, StateProviderFactory},
rpc::{
compat::engine::payload::block_to_payload,
eth::EthApi,
types::engine::{ExecutionPayload, ExecutionPayloadSidecar, PayloadError},
},
@ -170,6 +171,14 @@ impl EngineTypes for CustomEngineTypes {
type ExecutionPayloadEnvelopeV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadEnvelopeV3 = ExecutionPayloadEnvelopeV3;
type ExecutionPayloadEnvelopeV4 = ExecutionPayloadEnvelopeV4;
fn block_to_payload(
block: SealedBlockFor<
<<Self::BuiltPayload as reth_node_api::BuiltPayload>::Primitives as reth_node_api::NodePrimitives>::Block,
>,
) -> (ExecutionPayload, ExecutionPayloadSidecar) {
block_to_payload(block)
}
}
/// Custom engine validator