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
144impl NewPayloadError {
145 #[inline]
147 pub const fn is_block_hash_mismatch(&self) -> bool {
148 matches!(self, Self::Eth(PayloadError::BlockHash { .. }))
149 }
150
151 #[inline]
153 pub const fn is_invalid_versioned_hashes(&self) -> bool {
154 matches!(self, Self::Eth(PayloadError::InvalidVersionedHashes))
155 }
156}
157
158impl From<NewPayloadError> for PayloadStatusEnum {
159 fn from(error: NewPayloadError) -> Self {
160 Self::Invalid { validation_error: error.to_string() }
161 }
162}
163
164impl EngineObjectValidationError {
165 pub fn invalid_params<E>(error: E) -> Self
167 where
168 E: core::error::Error + Send + Sync + 'static,
169 {
170 Self::InvalidParams(Box::new(error))
171 }
172}
173
174#[derive(thiserror::Error, Debug)]
176pub enum InvalidPayloadAttributesError {
177 #[error("invalid timestamp")]
179 InvalidTimestamp,
180 #[error("Invalid params: {0}")]
182 InvalidParams(#[from] Box<dyn core::error::Error + Send + Sync>),
183}
184
185impl From<InvalidPayloadAttributesError> for ForkchoiceUpdateError {
186 fn from(_: InvalidPayloadAttributesError) -> Self {
187 Self::UpdatedInvalidPayloadAttributes
188 }
189}