feat: add ChainSpec AT to EngineTypes (#11054)

This commit is contained in:
Arsenii Kulikov
2024-09-23 18:02:57 +03:00
committed by GitHub
parent faca096263
commit cf294ce397
8 changed files with 14 additions and 8 deletions

1
Cargo.lock generated
View File

@ -6990,7 +6990,6 @@ name = "reth-engine-primitives"
version = "1.0.7"
dependencies = [
"alloy-primitives",
"reth-chainspec",
"reth-execution-types",
"reth-payload-primitives",
"reth-primitives",

View File

@ -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

View File

@ -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,
@ -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.
@ -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>;

View File

@ -36,6 +36,8 @@ impl PayloadTypes for EthEngineTypes {
}
impl EngineTypes for EthEngineTypes {
type ChainSpec = ChainSpec;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;

View File

@ -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
@ -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;

View File

@ -27,6 +27,8 @@ impl PayloadTypes for OptimismEngineTypes {
}
impl EngineTypes for OptimismEngineTypes {
type ChainSpec = ChainSpec;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = OptimismExecutionPayloadEnvelopeV3;

View File

@ -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`].
@ -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`

View File

@ -167,6 +167,8 @@ impl PayloadTypes for CustomEngineTypes {
}
impl EngineTypes for CustomEngineTypes {
type ChainSpec = ChainSpec;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;