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: add ChainSpec AT to EngineTypes #11054

Merged
merged 2 commits into from
Sep 23, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/engine/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ workspace = true

[dependencies]
# reth
reth-chainspec.workspace = true
reth-execution-types.workspace = true
reth-payload-primitives.workspace = true
reth-primitives.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions crates/engine/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
mod invalid_block_hook;
pub use invalid_block_hook::InvalidBlockHook;

use reth_chainspec::ChainSpec;
pub use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes,
PayloadTypes,
Expand All @@ -32,6 +31,9 @@ pub trait EngineTypes:
+ Serialize
+ 'static
{
/// The chain specification of the node.
type ChainSpec: Send + Sync;

/// Execution Payload V1 type.
type ExecutionPayloadV1: DeserializeOwned + Serialize + Clone + Unpin + Send + Sync + 'static;
/// Execution Payload V2 type.
Expand All @@ -44,7 +46,7 @@ pub trait EngineTypes:
/// Validates the presence or exclusion of fork-specific fields based on the payload attributes
/// and the message version.
fn validate_version_specific_fields(
chain_spec: &ChainSpec,
chain_spec: &Self::ChainSpec,
version: EngineApiMessageVersion,
payload_or_attrs: PayloadOrAttributes<'_, Self::PayloadAttributes>,
) -> Result<(), EngineObjectValidationError>;
Expand Down
2 changes: 2 additions & 0 deletions crates/ethereum/engine-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl PayloadTypes for EthEngineTypes {
}

impl EngineTypes for EthEngineTypes {
type ChainSpec = ChainSpec;

type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
Expand Down
4 changes: 2 additions & 2 deletions crates/node/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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<ChainSpec = Self::ChainSpec>;
}

/// A helper trait that is downstream of the [`NodeTypesWithEngine`] trait and adds database to the
Expand Down Expand Up @@ -166,7 +166,7 @@ where
impl<P, E, C> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C>
where
P: NodePrimitives + Send + Sync + Unpin + 'static,
E: EngineTypes + Send + Sync + Unpin,
E: EngineTypes<ChainSpec = C> + Send + Sync + Unpin,
C: EthChainSpec,
{
type Engine = E;
Expand Down
2 changes: 2 additions & 0 deletions crates/optimism/node/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ impl PayloadTypes for OptimismEngineTypes {
}

impl EngineTypes for OptimismEngineTypes {
type ChainSpec = ChainSpec;

type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = OptimismExecutionPayloadEnvelopeV3;
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct EngineApiInner<Provider, EngineT: EngineTypes, Pool> {
impl<Provider, EngineT, Pool> EngineApi<Provider, EngineT, Pool>
where
Provider: HeaderProvider + BlockReader + StateProviderFactory + EvmEnvProvider + 'static,
EngineT: EngineTypes,
EngineT: EngineTypes<ChainSpec = ChainSpec>,
Pool: TransactionPool + 'static,
{
/// Create new instance of [`EngineApi`].
Expand Down Expand Up @@ -622,7 +622,7 @@ where
impl<Provider, EngineT, Pool> EngineApiServer<EngineT> for EngineApi<Provider, EngineT, Pool>
where
Provider: HeaderProvider + BlockReader + StateProviderFactory + EvmEnvProvider + 'static,
EngineT: EngineTypes,
EngineT: EngineTypes<ChainSpec = ChainSpec>,
Pool: TransactionPool + 'static,
{
/// Handler for `engine_newPayloadV1`
Expand Down
2 changes: 2 additions & 0 deletions examples/custom-engine-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ impl PayloadTypes for CustomEngineTypes {
}

impl EngineTypes for CustomEngineTypes {
type ChainSpec = ChainSpec;

type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
Expand Down
Loading