Skip to main content

signet_cold/
error.rs

1//! Error types for cold storage operations.
2
3/// Result type alias for cold storage operations.
4pub type ColdResult<T, E = ColdStorageError> = Result<T, E>;
5
6/// Error type for cold storage operations.
7#[derive(Debug, thiserror::Error)]
8pub enum ColdStorageError {
9    /// An error occurred in the storage backend.
10    #[error("Backend error: {0}")]
11    Backend(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
12
13    /// The requested resource was not found.
14    #[error("Not found: {0}")]
15    NotFound(String),
16
17    /// The storage task was cancelled.
18    #[error("Task cancelled")]
19    Cancelled,
20
21    /// The cold storage task cannot keep up with incoming requests.
22    ///
23    /// The channel is full, indicating transient backpressure. The cold storage
24    /// task is still running but processing requests slower than they arrive.
25    ///
26    /// Callers may:
27    /// - Accept the gap (hot storage is authoritative) and repair later
28    /// - Retry after a delay with exponential backoff
29    /// - Increase channel capacity at construction time
30    #[error("cold storage backpressure: channel full")]
31    Backpressure,
32
33    /// The query matched more logs than the caller-specified `max_logs` limit.
34    ///
35    /// The query is rejected entirely rather than returning a partial result.
36    /// Callers should narrow the filter (smaller block range, more specific
37    /// address/topic filters) or increase the limit.
38    #[error("too many logs: query exceeds {limit}")]
39    TooManyLogs {
40        /// The limit that was exceeded.
41        limit: usize,
42    },
43
44    /// The streaming operation exceeded its deadline.
45    ///
46    /// The backend enforces a wall-clock limit on streaming operations
47    /// to prevent unbounded resource acquisition. Partial results may
48    /// have been delivered before this error.
49    #[error("stream deadline exceeded")]
50    StreamDeadlineExceeded,
51
52    /// A reorg was detected during a streaming operation.
53    ///
54    /// The anchor block hash changed between chunks, indicating that
55    /// the data being streamed may no longer be consistent. Partial
56    /// results may have been delivered before this error.
57    #[error("reorg detected during streaming")]
58    ReorgDetected,
59
60    /// The cold storage task has terminated.
61    ///
62    /// The channel is closed because the task has stopped (panic, cancellation,
63    /// or shutdown). This is persistent: all subsequent dispatches will fail
64    /// until the task is restarted.
65    ///
66    /// Hot storage remains consistent and authoritative. Cold storage can be
67    /// replayed from hot storage after task recovery.
68    #[error("cold storage task terminated: channel closed")]
69    TaskTerminated,
70}
71
72impl ColdStorageError {
73    /// Create a new backend error from any error type.
74    pub fn backend<E>(error: E) -> Self
75    where
76        E: core::error::Error + Send + Sync + 'static,
77    {
78        Self::Backend(Box::new(error))
79    }
80}