mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
chore(payload): Move ExecutionPayloadValidator into reth-ethereum-payload-builder (#14751)
This commit is contained in:
75
crates/ethereum/node/src/engine.rs
Normal file
75
crates/ethereum/node/src/engine.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
//! Validates execution payload wrt Ethereum Execution Engine API version.
|
||||
|
||||
use alloy_rpc_types_engine::ExecutionData;
|
||||
pub use alloy_rpc_types_engine::{
|
||||
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4,
|
||||
ExecutionPayloadV1, PayloadAttributes as EthPayloadAttributes,
|
||||
};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_engine_primitives::{EngineTypes, EngineValidator, PayloadValidator};
|
||||
use reth_ethereum_payload_builder::EthereumExecutionPayloadValidator;
|
||||
use reth_payload_primitives::{
|
||||
validate_version_specific_fields, EngineApiMessageVersion, EngineObjectValidationError,
|
||||
NewPayloadError, PayloadOrAttributes,
|
||||
};
|
||||
use reth_primitives::{Block, RecoveredBlock};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Validator for the ethereum engine API.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EthereumEngineValidator {
|
||||
inner: EthereumExecutionPayloadValidator<ChainSpec>,
|
||||
}
|
||||
|
||||
impl EthereumEngineValidator {
|
||||
/// Instantiates a new validator.
|
||||
pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
|
||||
Self { inner: EthereumExecutionPayloadValidator::new(chain_spec) }
|
||||
}
|
||||
|
||||
/// Returns the chain spec used by the validator.
|
||||
#[inline]
|
||||
fn chain_spec(&self) -> &ChainSpec {
|
||||
self.inner.chain_spec()
|
||||
}
|
||||
}
|
||||
|
||||
impl PayloadValidator for EthereumEngineValidator {
|
||||
type Block = Block;
|
||||
type ExecutionData = ExecutionData;
|
||||
|
||||
fn ensure_well_formed_payload(
|
||||
&self,
|
||||
payload: ExecutionData,
|
||||
) -> Result<RecoveredBlock<Self::Block>, NewPayloadError> {
|
||||
let sealed_block = self.inner.ensure_well_formed_payload(payload)?;
|
||||
sealed_block.try_recover().map_err(|e| NewPayloadError::Other(e.into()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<Types> EngineValidator<Types> for EthereumEngineValidator
|
||||
where
|
||||
Types: EngineTypes<PayloadAttributes = EthPayloadAttributes, ExecutionData = ExecutionData>,
|
||||
{
|
||||
fn validate_version_specific_fields(
|
||||
&self,
|
||||
version: EngineApiMessageVersion,
|
||||
payload_or_attrs: PayloadOrAttributes<'_, Self::ExecutionData, EthPayloadAttributes>,
|
||||
) -> Result<(), EngineObjectValidationError> {
|
||||
validate_version_specific_fields(self.chain_spec(), version, payload_or_attrs)
|
||||
}
|
||||
|
||||
fn ensure_well_formed_attributes(
|
||||
&self,
|
||||
version: EngineApiMessageVersion,
|
||||
attributes: &EthPayloadAttributes,
|
||||
) -> Result<(), EngineObjectValidationError> {
|
||||
validate_version_specific_fields(
|
||||
self.chain_spec(),
|
||||
version,
|
||||
PayloadOrAttributes::<Self::ExecutionData, EthPayloadAttributes>::PayloadAttributes(
|
||||
attributes,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -24,3 +24,6 @@ pub mod node;
|
||||
pub use node::EthereumNode;
|
||||
|
||||
pub mod payload;
|
||||
|
||||
pub mod engine;
|
||||
pub use engine::EthereumEngineValidator;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
//! Ethereum Node types config.
|
||||
|
||||
pub use crate::payload::EthereumPayloadBuilder;
|
||||
pub use crate::{payload::EthereumPayloadBuilder, EthereumEngineValidator};
|
||||
use crate::{EthEngineTypes, EthEvmConfig};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_consensus::{ConsensusError, FullConsensus};
|
||||
use reth_ethereum_consensus::EthBeaconConsensus;
|
||||
pub use reth_ethereum_engine_primitives::EthereumEngineValidator;
|
||||
use reth_ethereum_engine_primitives::{
|
||||
EthBuiltPayload, EthPayloadAttributes, EthPayloadBuilderAttributes,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user