mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-08 14:05:16 -05:00
83 lines
2.8 KiB
Rust
83 lines
2.8 KiB
Rust
//! 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::{EngineValidator, PayloadValidator};
|
|
use reth_ethereum_payload_builder::EthereumExecutionPayloadValidator;
|
|
use reth_ethereum_primitives::Block;
|
|
use reth_node_api::PayloadTypes;
|
|
use reth_payload_primitives::{
|
|
validate_execution_requests, validate_version_specific_fields, EngineApiMessageVersion,
|
|
EngineObjectValidationError, NewPayloadError, PayloadOrAttributes,
|
|
};
|
|
use reth_primitives_traits::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: PayloadTypes<PayloadAttributes = EthPayloadAttributes, ExecutionData = ExecutionData>,
|
|
{
|
|
fn validate_version_specific_fields(
|
|
&self,
|
|
version: EngineApiMessageVersion,
|
|
payload_or_attrs: PayloadOrAttributes<'_, Self::ExecutionData, EthPayloadAttributes>,
|
|
) -> Result<(), EngineObjectValidationError> {
|
|
payload_or_attrs
|
|
.execution_requests()
|
|
.map(|requests| validate_execution_requests(requests))
|
|
.transpose()?;
|
|
|
|
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,
|
|
),
|
|
)
|
|
}
|
|
}
|