Skip to content

Commit

Permalink
feat: introduce payload types (paradigmxyz#8756)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
jn and mattsse authored Jun 11, 2024
1 parent 92d2f29 commit 268e768
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
13 changes: 7 additions & 6 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use futures_util::Future;
use reth::{
api::{BuiltPayload, EngineTypes, FullNodeComponents, PayloadBuilderAttributes},
builder::FullNode,
payload::PayloadTypes,
providers::{BlockReader, BlockReaderIdExt, CanonStateSubscriptions, StageCheckpointReader},
rpc::types::engine::PayloadStatusEnum,
};
Expand Down Expand Up @@ -65,12 +66,12 @@ where
&mut self,
length: u64,
tx_generator: impl Fn(u64) -> Pin<Box<dyn Future<Output = Bytes>>>,
attributes_generator: impl Fn(u64) -> <Node::Engine as EngineTypes>::PayloadBuilderAttributes
attributes_generator: impl Fn(u64) -> <Node::Engine as PayloadTypes>::PayloadBuilderAttributes
+ Copy,
) -> eyre::Result<
Vec<(
<Node::Engine as EngineTypes>::BuiltPayload,
<Node::Engine as EngineTypes>::PayloadBuilderAttributes,
<Node::Engine as PayloadTypes>::PayloadBuilderAttributes,
)>,
>
where
Expand All @@ -96,10 +97,10 @@ where
/// It triggers the resolve payload via engine api and expects the built payload event.
pub async fn new_payload(
&mut self,
attributes_generator: impl Fn(u64) -> <Node::Engine as EngineTypes>::PayloadBuilderAttributes,
attributes_generator: impl Fn(u64) -> <Node::Engine as PayloadTypes>::PayloadBuilderAttributes,
) -> eyre::Result<(
<<Node as NodeTypes>::Engine as EngineTypes>::BuiltPayload,
<<Node as NodeTypes>::Engine as EngineTypes>::PayloadBuilderAttributes,
<<Node as NodeTypes>::Engine as PayloadTypes>::PayloadBuilderAttributes,
)>
where
<Node::Engine as EngineTypes>::ExecutionPayloadV3:
Expand All @@ -121,10 +122,10 @@ where
pub async fn advance_block(
&mut self,
versioned_hashes: Vec<B256>,
attributes_generator: impl Fn(u64) -> <Node::Engine as EngineTypes>::PayloadBuilderAttributes,
attributes_generator: impl Fn(u64) -> <Node::Engine as PayloadTypes>::PayloadBuilderAttributes,
) -> eyre::Result<(
<Node::Engine as EngineTypes>::BuiltPayload,
<<Node as NodeTypes>::Engine as EngineTypes>::PayloadBuilderAttributes,
<<Node as NodeTypes>::Engine as PayloadTypes>::PayloadBuilderAttributes,
)>
where
<Node::Engine as EngineTypes>::ExecutionPayloadV3:
Expand Down
19 changes: 5 additions & 14 deletions crates/engine-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,17 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use core::fmt;
use reth_primitives::ChainSpec;

use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, EngineObjectValidationError, PayloadAttributes,
PayloadBuilderAttributes, PayloadOrAttributes,
BuiltPayload, EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes,
PayloadTypes,
};

use reth_primitives::ChainSpec;
use serde::{de::DeserializeOwned, ser::Serialize};

/// The types that are used by the engine API.
pub trait EngineTypes:
DeserializeOwned + Serialize + fmt::Debug + Unpin + Send + Sync + Clone
PayloadTypes + DeserializeOwned + Serialize + fmt::Debug + Unpin + Send + Sync + Clone
{
/// The RPC payload attributes type the CL node emits via the engine API.
type PayloadAttributes: PayloadAttributes + Unpin;

/// The payload attributes type that contains information about a running payload job.
type PayloadBuilderAttributes: PayloadBuilderAttributes<RpcPayloadAttributes = Self::PayloadAttributes>
+ Clone
+ Unpin;

/// The built payload type.
type BuiltPayload: BuiltPayload
+ Clone
Expand Down
7 changes: 5 additions & 2 deletions crates/ethereum/engine-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use payload::{EthBuiltPayload, EthPayloadBuilderAttributes};
use reth_engine_primitives::EngineTypes;
use reth_payload_primitives::{
validate_version_specific_fields, EngineApiMessageVersion, EngineObjectValidationError,
PayloadOrAttributes,
PayloadOrAttributes, PayloadTypes,
};
use reth_primitives::ChainSpec;
use reth_rpc_types::{
Expand All @@ -30,9 +30,12 @@ use reth_rpc_types::{
#[non_exhaustive]
pub struct EthEngineTypes;

impl EngineTypes for EthEngineTypes {
impl PayloadTypes for EthEngineTypes {
type PayloadAttributes = EthPayloadAttributes;
type PayloadBuilderAttributes = EthPayloadBuilderAttributes;
}

impl EngineTypes for EthEngineTypes {
type BuiltPayload = EthBuiltPayload;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
Expand Down
7 changes: 5 additions & 2 deletions crates/optimism/node/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reth_node_api::{
payload::{
validate_parent_beacon_block_root_presence, EngineApiMessageVersion,
EngineObjectValidationError, MessageValidationKind, PayloadOrAttributes,
EngineObjectValidationError, MessageValidationKind, PayloadOrAttributes, PayloadTypes,
VersionSpecificValidationError,
},
EngineTypes,
Expand All @@ -21,9 +21,12 @@ use reth_rpc_types::{
#[non_exhaustive]
pub struct OptimismEngineTypes;

impl EngineTypes for OptimismEngineTypes {
impl PayloadTypes for OptimismEngineTypes {
type PayloadAttributes = OptimismPayloadAttributes;
type PayloadBuilderAttributes = OptimismPayloadBuilderAttributes;
}

impl EngineTypes for OptimismEngineTypes {
type BuiltPayload = OptimismBuiltPayload;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
Expand Down
11 changes: 11 additions & 0 deletions crates/payload/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ pub use payload::PayloadOrAttributes;
use reth_primitives::ChainSpec;
use std::fmt::Debug;

/// The types that are used by the engine API.
pub trait PayloadTypes: Send + Sync + Unpin {
/// The RPC payload attributes type the CL node emits via the engine API.
type PayloadAttributes: PayloadAttributes + Unpin;

/// The payload attributes type that contains information about a running payload job.
type PayloadBuilderAttributes: PayloadBuilderAttributes<RpcPayloadAttributes = Self::PayloadAttributes>
+ Clone
+ Unpin;
}

/// Validates the timestamp depending on the version called:
///
/// * If V2, this ensures that the payload timestamp is pre-Cancun.
Expand Down
6 changes: 5 additions & 1 deletion examples/custom-engine-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

use reth::{
api::PayloadTypes,
builder::{
components::{ComponentsBuilder, PayloadServiceBuilder},
node::NodeTypes,
Expand Down Expand Up @@ -162,9 +163,12 @@ impl PayloadBuilderAttributes for CustomPayloadBuilderAttributes {
#[non_exhaustive]
pub struct CustomEngineTypes;

impl EngineTypes for CustomEngineTypes {
impl PayloadTypes for CustomEngineTypes {
type PayloadAttributes = CustomPayloadAttributes;
type PayloadBuilderAttributes = CustomPayloadBuilderAttributes;
}

impl EngineTypes for CustomEngineTypes {
type BuiltPayload = EthBuiltPayload;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
Expand Down

0 comments on commit 268e768

Please sign in to comment.