reth_engine_primitives/
lib.rs1#![doc(
4 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
5 html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
6 issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
7)]
8#![cfg_attr(not(test), warn(unused_crate_dependencies))]
9#![cfg_attr(docsrs, feature(doc_cfg))]
10#![cfg_attr(not(feature = "std"), no_std)]
11
12extern crate alloc;
13
14use alloy_consensus::BlockHeader;
15use reth_errors::ConsensusError;
16use reth_payload_primitives::{
17 EngineApiMessageVersion, EngineObjectValidationError, InvalidPayloadAttributesError,
18 NewPayloadError, PayloadAttributes, PayloadOrAttributes, PayloadTypes,
19};
20use reth_primitives_traits::{Block, RecoveredBlock, SealedBlock};
21use reth_trie_common::HashedPostState;
22use serde::{de::DeserializeOwned, Serialize};
23
24#[cfg(feature = "std")]
26pub use reth_evm::{ConfigureEngineEvm, ExecutableTxIterator, ExecutableTxTuple};
27pub use reth_payload_primitives::ExecutionPayload;
28
29mod error;
30pub use error::*;
31
32mod forkchoice;
33pub use forkchoice::{ForkchoiceStateHash, ForkchoiceStateTracker, ForkchoiceStatus};
34
35#[cfg(feature = "std")]
36mod message;
37#[cfg(feature = "std")]
38pub use message::*;
39
40mod event;
41pub use event::*;
42
43mod invalid_block_hook;
44pub use invalid_block_hook::{InvalidBlockHook, InvalidBlockHooks, NoopInvalidBlockHook};
45
46pub mod config;
47pub use config::*;
48
49pub trait EngineTypes:
60 PayloadTypes<
61 BuiltPayload: TryInto<Self::ExecutionPayloadEnvelopeV1>
62 + TryInto<Self::ExecutionPayloadEnvelopeV2>
63 + TryInto<Self::ExecutionPayloadEnvelopeV3>
64 + TryInto<Self::ExecutionPayloadEnvelopeV4>
65 + TryInto<Self::ExecutionPayloadEnvelopeV5>
66 + TryInto<Self::ExecutionPayloadEnvelopeV6>,
67 > + DeserializeOwned
68 + Serialize
69{
70 type ExecutionPayloadEnvelopeV1: DeserializeOwned
72 + Serialize
73 + Clone
74 + Unpin
75 + Send
76 + Sync
77 + 'static;
78 type ExecutionPayloadEnvelopeV2: DeserializeOwned
80 + Serialize
81 + Clone
82 + Unpin
83 + Send
84 + Sync
85 + 'static;
86 type ExecutionPayloadEnvelopeV3: DeserializeOwned
88 + Serialize
89 + Clone
90 + Unpin
91 + Send
92 + Sync
93 + 'static;
94 type ExecutionPayloadEnvelopeV4: DeserializeOwned
96 + Serialize
97 + Clone
98 + Unpin
99 + Send
100 + Sync
101 + 'static;
102 type ExecutionPayloadEnvelopeV5: DeserializeOwned
104 + Serialize
105 + Clone
106 + Unpin
107 + Send
108 + Sync
109 + 'static;
110 type ExecutionPayloadEnvelopeV6: DeserializeOwned
112 + Serialize
113 + Clone
114 + Unpin
115 + Send
116 + Sync
117 + 'static;
118}
119
120pub trait EngineApiValidator<Types: PayloadTypes>: Send + Sync + Unpin + 'static {
122 fn validate_version_specific_fields(
125 &self,
126 version: EngineApiMessageVersion,
127 payload_or_attrs: PayloadOrAttributes<'_, Types::ExecutionData, Types::PayloadAttributes>,
128 ) -> Result<(), EngineObjectValidationError>;
129
130 fn ensure_well_formed_attributes(
132 &self,
133 version: EngineApiMessageVersion,
134 attributes: &Types::PayloadAttributes,
135 ) -> Result<(), EngineObjectValidationError>;
136}
137
138#[auto_impl::auto_impl(&, Arc)]
140pub trait PayloadValidator<Types: PayloadTypes>: Send + Sync + Unpin + 'static {
141 type Block: Block;
143
144 fn convert_payload_to_block(
155 &self,
156 payload: Types::ExecutionData,
157 ) -> Result<SealedBlock<Self::Block>, NewPayloadError>;
158
159 fn ensure_well_formed_payload(
168 &self,
169 payload: Types::ExecutionData,
170 ) -> Result<RecoveredBlock<Self::Block>, NewPayloadError> {
171 let sealed_block = self.convert_payload_to_block(payload)?;
172 sealed_block.try_recover().map_err(|e| NewPayloadError::Other(e.into()))
173 }
174
175 fn validate_block_post_execution_with_hashed_state(
177 &self,
178 _state_updates: &HashedPostState,
179 _block: &RecoveredBlock<Self::Block>,
180 ) -> Result<(), ConsensusError> {
181 Ok(())
183 }
184
185 fn validate_payload_attributes_against_header(
195 &self,
196 attr: &Types::PayloadAttributes,
197 header: &<Self::Block as Block>::Header,
198 ) -> Result<(), InvalidPayloadAttributesError> {
199 if attr.timestamp() <= header.timestamp() {
200 return Err(InvalidPayloadAttributesError::InvalidTimestamp);
201 }
202 Ok(())
203 }
204}