reth_engine_tree/tree/
error.rs1use crate::tree::payload_processor::bal::BalExecutionError;
4use alloy_consensus::BlockHeader;
5use reth_consensus::ConsensusError;
6use reth_errors::{BlockExecutionError, BlockValidationError, ProviderError};
7use reth_evm::execute::InternalBlockExecutionError;
8use reth_payload_primitives::NewPayloadError;
9use reth_primitives_traits::{Block, BlockBody, SealedBlock};
10
11#[derive(Debug, thiserror::Error)]
13pub enum AdvancePersistenceError {
14 #[error("persistence channel closed")]
16 ChannelClosed,
17 #[error(transparent)]
19 Provider(#[from] ProviderError),
20}
21
22#[derive(thiserror::Error)]
23#[error("Failed to insert block (hash={}, number={}, parent_hash={}): {}",
24 .block.hash(),
25 .block.number(),
26 .block.parent_hash(),
27 .kind)]
28struct InsertBlockErrorData<B: Block> {
29 block: SealedBlock<B>,
30 #[source]
31 kind: InsertBlockErrorKind,
32}
33
34impl<B: Block> std::fmt::Debug for InsertBlockErrorData<B> {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 f.debug_struct("InsertBlockError")
37 .field("error", &self.kind)
38 .field("hash", &self.block.hash())
39 .field("number", &self.block.number())
40 .field("parent_hash", &self.block.parent_hash())
41 .field("num_txs", &self.block.body().transactions().len())
42 .finish_non_exhaustive()
43 }
44}
45
46impl<B: Block> InsertBlockErrorData<B> {
47 const fn new(block: SealedBlock<B>, kind: InsertBlockErrorKind) -> Self {
48 Self { block, kind }
49 }
50
51 fn boxed(block: SealedBlock<B>, kind: InsertBlockErrorKind) -> Box<Self> {
52 Box::new(Self::new(block, kind))
53 }
54}
55
56#[derive(thiserror::Error)]
58#[error(transparent)]
59pub struct InsertBlockError<B: Block> {
60 inner: Box<InsertBlockErrorData<B>>,
61}
62
63impl<B: Block> InsertBlockError<B> {
66 pub fn new(block: SealedBlock<B>, kind: InsertBlockErrorKind) -> Self {
68 Self { inner: InsertBlockErrorData::boxed(block, kind) }
69 }
70
71 pub fn consensus_error(error: ConsensusError, block: SealedBlock<B>) -> Self {
73 Self::new(block, InsertBlockErrorKind::Consensus(error))
74 }
75
76 #[inline]
78 pub fn into_block(self) -> SealedBlock<B> {
79 self.inner.block
80 }
81
82 #[inline]
84 pub const fn kind(&self) -> &InsertBlockErrorKind {
85 &self.inner.kind
86 }
87
88 #[inline]
90 pub const fn block(&self) -> &SealedBlock<B> {
91 &self.inner.block
92 }
93
94 #[inline]
96 pub fn split(self) -> (SealedBlock<B>, InsertBlockErrorKind) {
97 let inner = *self.inner;
98 (inner.block, inner.kind)
99 }
100}
101
102impl<B: Block> std::fmt::Debug for InsertBlockError<B> {
103 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
104 std::fmt::Debug::fmt(&self.inner, f)
105 }
106}
107
108#[derive(Debug, thiserror::Error)]
110pub enum InsertBlockErrorKind {
111 #[error(transparent)]
113 Consensus(#[from] ConsensusError),
114 #[error(transparent)]
116 Execution(#[from] BlockExecutionError),
117 #[error(transparent)]
119 Provider(#[from] ProviderError),
120 #[error(transparent)]
122 Other(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
123}
124
125impl From<BalExecutionError> for InsertBlockErrorKind {
126 fn from(e: BalExecutionError) -> Self {
127 match e {
128 BalExecutionError::Consensus(inner) => Self::Consensus(inner),
129 BalExecutionError::Execution(inner) => Self::Execution(inner),
130 BalExecutionError::Provider(inner) => Self::Provider(inner),
131 BalExecutionError::Other(inner) => Self::Other(inner),
132 }
133 }
134}
135
136impl InsertBlockErrorKind {
137 pub fn ensure_validation_error(
145 self,
146 ) -> Result<InsertBlockValidationError, InsertBlockFatalError> {
147 match self {
148 Self::Consensus(err) => Ok(InsertBlockValidationError::Consensus(err)),
149 Self::Execution(err) => {
151 match err {
152 BlockExecutionError::Validation(err) => {
153 Ok(InsertBlockValidationError::Validation(err))
154 }
155 BlockExecutionError::Internal(error) => {
157 Err(InsertBlockFatalError::BlockExecutionError(error))
158 }
159 }
160 }
161 Self::Provider(err) => Err(InsertBlockFatalError::Provider(err)),
162 Self::Other(err) => Err(InternalBlockExecutionError::Other(err).into()),
163 }
164 }
165}
166
167#[derive(Debug, thiserror::Error)]
169pub enum InsertBlockFatalError {
170 #[error(transparent)]
172 Provider(#[from] ProviderError),
173 #[error(transparent)]
175 BlockExecutionError(#[from] InternalBlockExecutionError),
176}
177
178#[derive(Debug, thiserror::Error)]
180pub enum InsertBlockValidationError {
181 #[error(transparent)]
183 Consensus(#[from] ConsensusError),
184 #[error(transparent)]
186 Validation(#[from] BlockValidationError),
187}
188
189#[derive(Debug, thiserror::Error)]
191pub enum InsertPayloadError<B: Block> {
192 #[error(transparent)]
194 Block(#[from] InsertBlockError<B>),
195 #[error(transparent)]
197 Payload(#[from] NewPayloadError),
198}