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, doc_auto_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};
21use reth_trie_common::HashedPostState;
22use serde::{de::DeserializeOwned, Serialize};
23
24pub use reth_evm::{ConfigureEngineEvm, ExecutableTxIterator};
26pub use reth_payload_primitives::ExecutionPayload;
27
28mod error;
29pub use error::*;
30
31mod forkchoice;
32pub use forkchoice::{ForkchoiceStateHash, ForkchoiceStateTracker, ForkchoiceStatus};
33
34#[cfg(feature = "std")]
35mod message;
36#[cfg(feature = "std")]
37pub use message::*;
38
39mod event;
40pub use event::*;
41
42mod invalid_block_hook;
43pub use invalid_block_hook::{InvalidBlockHook, InvalidBlockHooks, NoopInvalidBlockHook};
44
45pub mod config;
46pub use config::*;
47
48pub trait EngineTypes:
59 PayloadTypes<
60 BuiltPayload: TryInto<Self::ExecutionPayloadEnvelopeV1>
61 + TryInto<Self::ExecutionPayloadEnvelopeV2>
62 + TryInto<Self::ExecutionPayloadEnvelopeV3>
63 + TryInto<Self::ExecutionPayloadEnvelopeV4>
64 + TryInto<Self::ExecutionPayloadEnvelopeV5>,
65 > + DeserializeOwned
66 + Serialize
67{
68 type ExecutionPayloadEnvelopeV1: DeserializeOwned
70 + Serialize
71 + Clone
72 + Unpin
73 + Send
74 + Sync
75 + 'static;
76 type ExecutionPayloadEnvelopeV2: DeserializeOwned
78 + Serialize
79 + Clone
80 + Unpin
81 + Send
82 + Sync
83 + 'static;
84 type ExecutionPayloadEnvelopeV3: DeserializeOwned
86 + Serialize
87 + Clone
88 + Unpin
89 + Send
90 + Sync
91 + 'static;
92 type ExecutionPayloadEnvelopeV4: DeserializeOwned
94 + Serialize
95 + Clone
96 + Unpin
97 + Send
98 + Sync
99 + 'static;
100 type ExecutionPayloadEnvelopeV5: DeserializeOwned
102 + Serialize
103 + Clone
104 + Unpin
105 + Send
106 + Sync
107 + 'static;
108}
109
110pub trait EngineApiValidator<Types: PayloadTypes>: Send + Sync + Unpin + 'static {
112 fn validate_version_specific_fields(
115 &self,
116 version: EngineApiMessageVersion,
117 payload_or_attrs: PayloadOrAttributes<'_, Types::ExecutionData, Types::PayloadAttributes>,
118 ) -> Result<(), EngineObjectValidationError>;
119
120 fn ensure_well_formed_attributes(
122 &self,
123 version: EngineApiMessageVersion,
124 attributes: &Types::PayloadAttributes,
125 ) -> Result<(), EngineObjectValidationError>;
126}
127
128#[auto_impl::auto_impl(&, Arc)]
130pub trait PayloadValidator<Types: PayloadTypes>: Send + Sync + Unpin + 'static {
131 type Block: Block;
133
134 fn ensure_well_formed_payload(
143 &self,
144 payload: Types::ExecutionData,
145 ) -> Result<RecoveredBlock<Self::Block>, NewPayloadError>;
146
147 fn validate_block_post_execution_with_hashed_state(
149 &self,
150 _state_updates: &HashedPostState,
151 _block: &RecoveredBlock<Self::Block>,
152 ) -> Result<(), ConsensusError> {
153 Ok(())
155 }
156
157 fn validate_payload_attributes_against_header(
167 &self,
168 attr: &Types::PayloadAttributes,
169 header: &<Self::Block as Block>::Header,
170 ) -> Result<(), InvalidPayloadAttributesError> {
171 if attr.timestamp() <= header.timestamp() {
172 return Err(InvalidPayloadAttributesError::InvalidTimestamp);
173 }
174 Ok(())
175 }
176}