reth_payload_primitives/
error.rs1use alloc::{boxed::Box, string::ToString};
4use alloy_primitives::B256;
5use alloy_rpc_types_engine::{ForkchoiceUpdateError, PayloadError, PayloadStatusEnum};
6use core::error;
7use reth_errors::{BlockExecutionError, ProviderError, RethError};
8use tokio::sync::{mpsc, oneshot};
9
10#[derive(Debug, thiserror::Error)]
12pub enum PayloadBuilderError {
13 #[error("missing parent header: {0}")]
15 MissingParentHeader(B256),
16 #[error("missing parent block {0}")]
18 MissingParentBlock(B256),
19 #[error("sender has been dropped")]
21 ChannelClosed,
22 #[error("missing payload")]
24 MissingPayload,
25 #[error(transparent)]
27 Internal(#[from] RethError),
28 #[error("evm execution error: {0}")]
30 EvmExecutionError(Box<dyn core::error::Error + Send + Sync>),
31 #[error(transparent)]
33 Other(Box<dyn core::error::Error + Send + Sync>),
34}
35
36impl PayloadBuilderError {
37 pub fn evm<E>(error: E) -> Self
39 where
40 E: core::error::Error + Send + Sync + 'static,
41 {
42 Self::EvmExecutionError(Box::new(error))
43 }
44
45 pub fn other<E>(error: E) -> Self
47 where
48 E: core::error::Error + Send + Sync + 'static,
49 {
50 Self::Other(Box::new(error))
51 }
52}
53
54impl From<ProviderError> for PayloadBuilderError {
55 fn from(error: ProviderError) -> Self {
56 Self::Internal(RethError::Provider(error))
57 }
58}
59
60impl From<oneshot::error::RecvError> for PayloadBuilderError {
61 fn from(_: oneshot::error::RecvError) -> Self {
62 Self::ChannelClosed
63 }
64}
65
66impl From<BlockExecutionError> for PayloadBuilderError {
67 fn from(error: BlockExecutionError) -> Self {
68 Self::evm(error)
69 }
70}
71
72impl<T> From<mpsc::error::SendError<T>> for PayloadBuilderError {
73 fn from(_: mpsc::error::SendError<T>) -> Self {
74 Self::ChannelClosed
75 }
76}
77
78#[derive(thiserror::Error, Debug)]
84pub enum EngineObjectValidationError {
85 #[error("Payload validation error: {0}")]
88 Payload(VersionSpecificValidationError),
89
90 #[error("Payload attributes validation error: {0}")]
93 PayloadAttributes(VersionSpecificValidationError),
94
95 #[error("Unsupported fork")]
99 UnsupportedFork,
100 #[error("Invalid params: {0}")]
102 InvalidParams(#[from] Box<dyn core::error::Error + Send + Sync>),
103}
104
105#[derive(thiserror::Error, Debug)]
109pub enum VersionSpecificValidationError {
110 #[error("parent beacon block root not supported before V3")]
113 ParentBeaconBlockRootNotSupportedBeforeV3,
114 #[error("withdrawals not supported in V1")]
116 WithdrawalsNotSupportedInV1,
117 #[error("no withdrawals post-Shanghai")]
120 NoWithdrawalsPostShanghai,
121 #[error("withdrawals pre-Shanghai")]
124 HasWithdrawalsPreShanghai,
125 #[error("no parent beacon block root post-cancun")]
128 NoParentBeaconBlockRootPostCancun,
129 #[error("block access list not before V6")]
131 BlockAccessListNotSupportedBeforeV6,
132 #[error("no block access list post-Amsterdam")]
135 NoBlockAccessListPostAmsterdam,
136 #[error("block access list pre-Amsterdam")]
139 HasBlockAccessListPreAmsterdam,
140 #[error("slot number not before V6")]
142 SlotNumberNotSupportedBeforeV6,
143 #[error("no slot number post-Amsterdam")]
146 NoSlotNumberPostAmsterdam,
147 #[error("slot number pre-Amsterdam")]
150 HasSlotNumberPreAmsterdam,
151}
152
153#[derive(thiserror::Error, Debug)]
155pub enum NewPayloadError {
156 #[error(transparent)]
158 Eth(#[from] PayloadError),
159 #[error(transparent)]
161 Other(Box<dyn error::Error + Send + Sync>),
162}
163
164impl NewPayloadError {
165 #[inline]
167 pub fn other(err: impl error::Error + Send + Sync + 'static) -> Self {
168 Self::Other(Box::new(err))
169 }
170
171 #[inline]
173 pub const fn is_block_hash_mismatch(&self) -> bool {
174 matches!(self, Self::Eth(PayloadError::BlockHash { .. }))
175 }
176
177 #[inline]
179 pub const fn is_invalid_versioned_hashes(&self) -> bool {
180 matches!(self, Self::Eth(PayloadError::InvalidVersionedHashes))
181 }
182}
183
184impl From<NewPayloadError> for PayloadStatusEnum {
185 fn from(error: NewPayloadError) -> Self {
186 Self::Invalid { validation_error: error.to_string() }
187 }
188}
189
190impl EngineObjectValidationError {
191 pub fn invalid_params<E>(error: E) -> Self
193 where
194 E: core::error::Error + Send + Sync + 'static,
195 {
196 Self::InvalidParams(Box::new(error))
197 }
198}
199
200#[derive(thiserror::Error, Debug)]
202pub enum InvalidPayloadAttributesError {
203 #[error("invalid timestamp")]
205 InvalidTimestamp,
206 #[error("Invalid params: {0}")]
208 InvalidParams(#[from] Box<dyn core::error::Error + Send + Sync>),
209}
210
211impl From<InvalidPayloadAttributesError> for ForkchoiceUpdateError {
212 fn from(_: InvalidPayloadAttributesError) -> Self {
213 Self::UpdatedInvalidPayloadAttributes
214 }
215}