Skip to content

Commit

Permalink
Introduce Eth PayloadTypes Impl (paradigmxyz#11519)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
stevencartavia and mattsse authored Oct 7, 2024
1 parent 8ca5ec9 commit 9a732f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
31 changes: 25 additions & 6 deletions crates/ethereum/engine-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,40 @@ use reth_payload_primitives::{
/// The types used in the default mainnet ethereum beacon consensus engine.
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
#[non_exhaustive]
pub struct EthEngineTypes;
pub struct EthEngineTypes<T: PayloadTypes = EthPayloadTypes> {
_marker: std::marker::PhantomData<T>,
}

impl PayloadTypes for EthEngineTypes {
type BuiltPayload = EthBuiltPayload;
type PayloadAttributes = EthPayloadAttributes;
type PayloadBuilderAttributes = EthPayloadBuilderAttributes;
impl<T: PayloadTypes> PayloadTypes for EthEngineTypes<T> {
type BuiltPayload = T::BuiltPayload;
type PayloadAttributes = T::PayloadAttributes;
type PayloadBuilderAttributes = T::PayloadBuilderAttributes;
}

impl EngineTypes for EthEngineTypes {
impl<T: PayloadTypes> EngineTypes for EthEngineTypes<T>
where
T::BuiltPayload: TryInto<ExecutionPayloadV1>
+ TryInto<ExecutionPayloadEnvelopeV2>
+ TryInto<ExecutionPayloadEnvelopeV3>
+ TryInto<ExecutionPayloadEnvelopeV4>,
{
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
type ExecutionPayloadV4 = ExecutionPayloadEnvelopeV4;
}

/// A default payload type for [`EthEngineTypes`]
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
#[non_exhaustive]
pub struct EthPayloadTypes;

impl PayloadTypes for EthPayloadTypes {
type BuiltPayload = EthBuiltPayload;
type PayloadAttributes = EthPayloadAttributes;
type PayloadBuilderAttributes = EthPayloadBuilderAttributes;
}

/// Validator for the ethereum engine API.
#[derive(Debug, Clone)]
pub struct EthereumEngineValidator {
Expand Down
1 change: 1 addition & 0 deletions crates/node/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub trait NodeTypes: Send + Sync + Unpin + 'static {
pub trait NodeTypesWithEngine: NodeTypes {
/// The node's engine types, defining the interaction with the consensus engine.
type Engine: EngineTypes;
// type Engine: EngineTypes;
}

/// A helper trait that is downstream of the [`NodeTypesWithEngine`] trait and adds database to the
Expand Down

0 comments on commit 9a732f6

Please sign in to comment.