-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy patherror.rs
More file actions
134 lines (104 loc) · 4.2 KB
/
error.rs
File metadata and controls
134 lines (104 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use alloy::primitives::{B256, U256};
use thiserror::Error;
use crate::{types::BlsPublicKeyBytes, utils::ResponseReadError};
#[derive(Debug, Error)]
pub enum PbsError {
#[error("axum error: {0:?}")]
AxumError(#[from] axum::Error),
#[error("reqwest error: {0:?}")]
Reqwest(#[from] reqwest::Error),
#[error("json decode error: {err:?}, raw: {raw}")]
JsonDecode { err: serde_json::Error, raw: String },
#[error("error with request: {0}")]
GeneralRequest(String),
#[error("{0}")]
ReadResponse(#[from] ResponseReadError),
#[error("relay response error. Code: {code}, err: {error_msg:?}")]
RelayResponse { error_msg: String, code: u16 },
#[error("failed validating relay response: {0}")]
Validation(#[from] ValidationError),
#[error("URL parsing error: {0}")]
UrlParsing(#[from] url::ParseError),
#[error("tokio join error: {0}")]
TokioJoinError(#[from] tokio::task::JoinError),
}
impl PbsError {
pub fn is_timeout(&self) -> bool {
matches!(self, PbsError::Reqwest(err) if err.is_timeout())
}
/// Whether the error is retryable in requests to relays
pub fn should_retry(&self) -> bool {
match self {
PbsError::Reqwest(err) => {
// Retry on timeout or connection error
err.is_timeout() || err.is_connect()
}
PbsError::RelayResponse { code, .. } => match *code {
500..509 => true, // Retry on server errors
400 | 429 => false, // Do not retry if rate limited or bad request
_ => false,
},
_ => false,
}
}
pub fn is_not_found(&self) -> bool {
matches!(&self, PbsError::RelayResponse { code: 404, .. })
}
}
#[derive(Debug, Error, PartialEq, Eq)]
pub enum ValidationError {
#[error("empty blockhash")]
EmptyBlockhash,
#[error("pubkey mismatch: expected {expected} got {got}")]
PubkeyMismatch { expected: BlsPublicKeyBytes, got: BlsPublicKeyBytes },
#[error("parent hash mismatch: expected {expected} got {got}")]
ParentHashMismatch { expected: B256, got: B256 },
#[error("block hash mismatch: expected {expected} got {got}")]
BlockHashMismatch { expected: B256, got: B256 },
#[error(
"mismatch in KZG commitments: expected_blobs: {expected_blobs} got_blobs: {got_blobs} got_commitments: {got_commitments} got_proofs: {got_proofs}"
)]
KzgCommitments {
expected_blobs: usize,
got_blobs: usize,
got_commitments: usize,
got_proofs: usize,
},
#[error("mismatch in KZG blob commitment: expected: {expected} got: {got} index: {index}")]
KzgMismatch { expected: String, got: String, index: usize },
#[error("bid below minimum: min: {min} got {got}")]
BidTooLow { min: U256, got: U256 },
#[error("empty tx root")]
EmptyTxRoot,
#[error("failed signature verification")]
Sigverify,
#[error("wrong timestamp: expected {expected} got {got}")]
TimestampMismatch { expected: u64, got: u64 },
#[error("wrong block number: parent: {parent} header: {header}")]
BlockNumberMismatch { parent: u64, header: u64 },
#[error("invalid gas limit: parent: {parent} header: {header}")]
GasLimit { parent: u64, header: u64 },
#[error("payload mismatch: request: {request} response: {response}")]
PayloadVersionMismatch { request: &'static str, response: &'static str },
#[error("unsupported fork")]
UnsupportedFork,
}
#[derive(Debug, Error, PartialEq, Eq)]
pub enum SszValueError {
#[error("invalid payload length: required {required} but payload was {actual}")]
InvalidPayloadLength { required: usize, actual: usize },
#[error("unsupported fork")]
UnsupportedFork { name: String },
}
impl From<SszValueError> for PbsError {
fn from(err: SszValueError) -> Self {
match err {
SszValueError::InvalidPayloadLength { required, actual } => PbsError::GeneralRequest(
format!("invalid payload length: required {required} but payload was {actual}"),
),
SszValueError::UnsupportedFork { name } => {
PbsError::GeneralRequest(format!("unsupported fork: {name}"))
}
}
}
}