Skip to content

Commit cfd290a

Browse files
committed
address review nits
1 parent c311eaa commit cfd290a

6 files changed

Lines changed: 17 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/src/pbs/error.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloy::primitives::{B256, U256};
2+
use lh_types::ForkName;
23
use thiserror::Error;
34

45
use crate::{types::BlsPublicKeyBytes, utils::ResponseReadError};
@@ -116,6 +117,6 @@ pub enum SszValueError {
116117
#[error("invalid payload length: required {required} but payload was {actual}")]
117118
InvalidPayloadLength { required: usize, actual: usize },
118119

119-
#[error("unsupported fork")]
120-
UnsupportedFork { name: String },
120+
#[error("unsupported fork: {name}")]
121+
UnsupportedFork { name: ForkName },
121122
}

crates/common/src/pbs/types/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ pub type GetHeaderResponse = ForkVersionedResponse<SignedBuilderBid>;
5050

5151
pub type KzgCommitments = lh_types::KzgCommitments<MainnetEthSpec>;
5252

53-
pub type Uint256 = lh_types::Uint256;
54-
5553
/// Response params of GET
5654
/// `/eth/v1/builder/header/{slot}/{parent_hash}/{pubkey}`
5755
#[derive(Debug, Serialize, Deserialize, Clone)]

crates/common/src/utils.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::cell::Cell;
33
use std::{
44
net::Ipv4Addr,
55
str::FromStr,
6-
sync::LazyLock,
76
time::{SystemTime, UNIX_EPOCH},
87
};
98

@@ -644,7 +643,7 @@ pub fn get_accept_types(req_headers: &HeaderMap) -> eyre::Result<AcceptedEncodin
644643
}
645644

646645
if saw_any && !had_supported {
647-
return Err(eyre::eyre!("unsupported accept type"));
646+
eyre::bail!("unsupported accept type");
648647
}
649648

650649
// No accept header (or only q=0 rejections): fall back to the request
@@ -717,16 +716,10 @@ impl EncodingType {
717716
}
718717
}
719718

720-
/// Pre-built `Content-Type` header for this encoding. `HeaderValue` is
721-
/// not `const`-constructible in stable Rust, so the values are
722-
/// lazy-initialized once per process via `LazyLock` from static ASCII
723-
/// strings. Callers can clone the returned reference cheaply (the
724-
/// underlying bytes are shared).
719+
/// Pre-built `Content-Type` header for this encoding.
725720
pub fn content_type_header(&self) -> &'static HeaderValue {
726-
static JSON_HEADER: LazyLock<HeaderValue> =
727-
LazyLock::new(|| HeaderValue::from_static(APPLICATION_JSON));
728-
static SSZ_HEADER: LazyLock<HeaderValue> =
729-
LazyLock::new(|| HeaderValue::from_static(APPLICATION_OCTET_STREAM));
721+
static JSON_HEADER: HeaderValue = HeaderValue::from_static(APPLICATION_JSON);
722+
static SSZ_HEADER: HeaderValue = HeaderValue::from_static(APPLICATION_OCTET_STREAM);
730723
match self {
731724
EncodingType::Json => &JSON_HEADER,
732725
EncodingType::Ssz => &SSZ_HEADER,
@@ -917,7 +910,7 @@ fn get_ssz_value_offset_for_fork(fork: ForkName) -> Result<usize, SszValueError>
917910
<ExecutionRequests as ssz::Decode>::ssz_fixed_len())
918911
}
919912

920-
_ => Err(SszValueError::UnsupportedFork { name: fork.to_string() }),
913+
_ => Err(SszValueError::UnsupportedFork { name: fork }),
921914
}
922915
}
923916

crates/pbs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ tracing.workspace = true
3131
tree_hash.workspace = true
3232
url.workspace = true
3333
uuid.workspace = true
34+
thiserror.workspace = true

crates/pbs/src/error.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
use axum::{http::StatusCode, response::IntoResponse};
22
use cb_common::utils::BodyDeserializeError;
3+
use thiserror::Error;
34

4-
#[derive(Debug)]
5+
#[derive(Debug, Error)]
56
/// Errors that the PbsService returns to client
67
pub enum PbsClientError {
8+
#[error("no response from relays")]
79
NoResponse,
10+
#[error("no payload from relays")]
811
NoPayload,
12+
#[error("internal server error")]
913
Internal,
10-
DecodeError(String),
14+
#[error("failed to deserialize body: {0}")]
15+
DecodeError(#[from] BodyDeserializeError),
1116
}
1217

1318
impl PbsClientError {
@@ -21,12 +26,6 @@ impl PbsClientError {
2126
}
2227
}
2328

24-
impl From<BodyDeserializeError> for PbsClientError {
25-
fn from(e: BodyDeserializeError) -> Self {
26-
PbsClientError::DecodeError(format!("failed to deserialize body: {e}"))
27-
}
28-
}
29-
3029
impl IntoResponse for PbsClientError {
3130
fn into_response(self) -> axum::response::Response {
3231
let msg = match &self {

0 commit comments

Comments
 (0)