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::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
72#[derive(thiserror::Error, Debug)]
78pub enum EngineObjectValidationError {
79 #[error("Payload validation error: {0}")]
82 Payload(VersionSpecificValidationError),
83
84 #[error("Payload attributes validation error: {0}")]
87 PayloadAttributes(VersionSpecificValidationError),
88
89 #[error("Unsupported fork")]
93 UnsupportedFork,
94 #[error("Invalid params: {0}")]
96 InvalidParams(#[from] Box<dyn core::error::Error + Send + Sync>),
97}
98
99#[derive(thiserror::Error, Debug)]
103pub enum VersionSpecificValidationError {
104 #[error("parent beacon block root not supported before V3")]
107 ParentBeaconBlockRootNotSupportedBeforeV3,
108 #[error("withdrawals not supported in V1")]
110 WithdrawalsNotSupportedInV1,
111 #[error("no withdrawals post-Shanghai")]
114 NoWithdrawalsPostShanghai,
115 #[error("withdrawals pre-Shanghai")]
118 HasWithdrawalsPreShanghai,
119 #[error("no parent beacon block root post-cancun")]
122 NoParentBeaconBlockRootPostCancun,
123}
124
125#[derive(thiserror::Error, Debug)]
127pub enum NewPayloadError {
128 #[error(transparent)]
130 Eth(#[from] PayloadError),
131 #[error(transparent)]
133 Other(Box<dyn error::Error + Send + Sync>),
134}
135
136impl NewPayloadError {
137 #[inline]
139 pub fn other(err: impl error::Error + Send + Sync + 'static) -> Self {
140 Self::Other(Box::new(err))
141 }
142
143 #[inline]
145 pub const fn is_block_hash_mismatch(&self) -> bool {
146 matches!(self, Self::Eth(PayloadError::BlockHash { .. }))
147 }
148
149 #[inline]
151 pub const fn is_invalid_versioned_hashes(&self) -> bool {
152 matches!(self, Self::Eth(PayloadError::InvalidVersionedHashes))
153 }
154}
155
156impl From<NewPayloadError> for PayloadStatusEnum {
157 fn from(error: NewPayloadError) -> Self {
158 Self::Invalid { validation_error: error.to_string() }
159 }
160}
161
162impl EngineObjectValidationError {
163 pub fn invalid_params<E>(error: E) -> Self
165 where
166 E: core::error::Error + Send + Sync + 'static,
167 {
168 Self::InvalidParams(Box::new(error))
169 }
170}
171
172#[derive(thiserror::Error, Debug)]
174pub enum InvalidPayloadAttributesError {
175 #[error("invalid timestamp")]
177 InvalidTimestamp,
178 #[error("Invalid params: {0}")]
180 InvalidParams(#[from] Box<dyn core::error::Error + Send + Sync>),
181}
182
183impl From<InvalidPayloadAttributesError> for ForkchoiceUpdateError {
184 fn from(_: InvalidPayloadAttributesError) -> Self {
185 Self::UpdatedInvalidPayloadAttributes
186 }
187}