kona_engine/task_queue/tasks/forkchoice/
error.rs

1//! Contains error types for the [crate::ForkchoiceTask].
2
3use crate::{EngineTaskError, task_queue::tasks::task::EngineTaskErrorSeverity};
4use alloy_rpc_types_engine::PayloadStatusEnum;
5use alloy_transport::{RpcError, TransportErrorKind};
6use thiserror::Error;
7
8/// An error that occurs when running the [crate::ForkchoiceTask].
9#[derive(Debug, Error)]
10pub enum ForkchoiceTaskError {
11    /// The forkchoice update is not needed.
12    #[error("No forkchoice update needed")]
13    NoForkchoiceUpdateNeeded,
14    /// The engine is syncing.
15    #[error("Attempting to update forkchoice state while EL syncing")]
16    EngineSyncing,
17    /// The forkchoice update call to the engine api failed.
18    #[error("Forkchoice update engine api call failed")]
19    ForkchoiceUpdateFailed(RpcError<TransportErrorKind>),
20    /// The finalized head is behind the unsafe head.
21    #[error("Invalid forkchoice state: unsafe head {0} is ahead of finalized head {1}")]
22    FinalizedAheadOfUnsafe(u64, u64),
23    /// The forkchoice state is invalid.
24    #[error("Invalid forkchoice state")]
25    InvalidForkchoiceState,
26    /// The payload status is invalid.
27    #[error("Invalid payload status: {0}")]
28    InvalidPayloadStatus(String),
29    /// The payload status is unexpected.
30    #[error("Unexpected payload status: {0}")]
31    UnexpectedPayloadStatus(PayloadStatusEnum),
32}
33
34impl EngineTaskError for ForkchoiceTaskError {
35    fn severity(&self) -> EngineTaskErrorSeverity {
36        match self {
37            Self::NoForkchoiceUpdateNeeded => EngineTaskErrorSeverity::Temporary,
38            Self::EngineSyncing => EngineTaskErrorSeverity::Temporary,
39            Self::ForkchoiceUpdateFailed(_) => EngineTaskErrorSeverity::Temporary,
40            Self::FinalizedAheadOfUnsafe(_, _) => EngineTaskErrorSeverity::Critical,
41            Self::UnexpectedPayloadStatus(_) => EngineTaskErrorSeverity::Critical,
42            Self::InvalidForkchoiceState => EngineTaskErrorSeverity::Reset,
43            Self::InvalidPayloadStatus(_) => EngineTaskErrorSeverity::Reset,
44        }
45    }
46}