reth_engine_primitives/
lib.rs#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
mod error;
use core::fmt;
use alloy_consensus::BlockHeader;
use alloy_rpc_types_engine::{ExecutionPayload, ExecutionPayloadSidecar, PayloadError};
pub use error::BeaconOnNewPayloadError;
mod forkchoice;
pub use forkchoice::{ForkchoiceStateHash, ForkchoiceStateTracker, ForkchoiceStatus};
mod message;
pub use message::{BeaconEngineMessage, OnForkChoiceUpdated};
mod invalid_block_hook;
pub use invalid_block_hook::InvalidBlockHook;
pub use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes,
PayloadTypes,
};
use reth_payload_primitives::{InvalidPayloadAttributesError, PayloadAttributes};
use reth_primitives::SealedBlockFor;
use reth_primitives_traits::Block;
use serde::{de::DeserializeOwned, ser::Serialize};
pub trait EngineTypes:
PayloadTypes<
BuiltPayload: TryInto<Self::ExecutionPayloadEnvelopeV1>
+ TryInto<Self::ExecutionPayloadEnvelopeV2>
+ TryInto<Self::ExecutionPayloadEnvelopeV3>
+ TryInto<Self::ExecutionPayloadEnvelopeV4>,
> + DeserializeOwned
+ Serialize
+ 'static
{
type ExecutionPayloadEnvelopeV1: DeserializeOwned
+ Serialize
+ Clone
+ Unpin
+ Send
+ Sync
+ 'static;
type ExecutionPayloadEnvelopeV2: DeserializeOwned
+ Serialize
+ Clone
+ Unpin
+ Send
+ Sync
+ 'static;
type ExecutionPayloadEnvelopeV3: DeserializeOwned
+ Serialize
+ Clone
+ Unpin
+ Send
+ Sync
+ 'static;
type ExecutionPayloadEnvelopeV4: DeserializeOwned
+ Serialize
+ Clone
+ Unpin
+ Send
+ Sync
+ 'static;
}
pub trait PayloadValidator: fmt::Debug + Send + Sync + Unpin + 'static {
type Block: Block;
fn ensure_well_formed_payload(
&self,
payload: ExecutionPayload,
sidecar: ExecutionPayloadSidecar,
) -> Result<SealedBlockFor<Self::Block>, PayloadError>;
}
pub trait EngineValidator<Types: EngineTypes>: PayloadValidator {
fn validate_version_specific_fields(
&self,
version: EngineApiMessageVersion,
payload_or_attrs: PayloadOrAttributes<'_, <Types as PayloadTypes>::PayloadAttributes>,
) -> Result<(), EngineObjectValidationError>;
fn ensure_well_formed_attributes(
&self,
version: EngineApiMessageVersion,
attributes: &<Types as PayloadTypes>::PayloadAttributes,
) -> Result<(), EngineObjectValidationError>;
fn validate_payload_attributes_against_header(
&self,
attr: &<Types as PayloadTypes>::PayloadAttributes,
header: &<Self::Block as Block>::Header,
) -> Result<(), InvalidPayloadAttributesError> {
if attr.timestamp() <= header.timestamp() {
return Err(InvalidPayloadAttributesError::InvalidTimestamp);
}
Ok(())
}
}