Skip to content

Commit 4bc807b

Browse files
committed
make "accepts_ssz" and "accepts_json" inside handle_submit_block_impl
body to dedup (match pattern in get_header.rs) + some clippy warnings
1 parent fdaa06e commit 4bc807b

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

bin/tests/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn test_init_compose_file_pbs_service_structure() {
133133
// Config file must be mounted inside the container.
134134
let volumes = pbs["volumes"].as_sequence().expect("volumes is a list");
135135
assert!(
136-
volumes.iter().any(|v| v.as_str().map_or(false, |s| s.ends_with(":/cb-config.toml:ro"))),
136+
volumes.iter().any(|v| v.as_str().is_some_and(|s| s.ends_with(":/cb-config.toml:ro"))),
137137
"config must be mounted at /cb-config.toml"
138138
);
139139

@@ -145,7 +145,7 @@ fn test_init_compose_file_pbs_service_structure() {
145145
// Port 18550 must be exposed.
146146
let ports = pbs["ports"].as_sequence().expect("ports is a list");
147147
assert!(
148-
ports.iter().any(|p| p.as_str().map_or(false, |s| s.contains("18550"))),
148+
ports.iter().any(|p| p.as_str().is_some_and(|s| s.contains("18550"))),
149149
"port 18550 must be exposed"
150150
);
151151

crates/pbs/src/routes/submit_block.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ async fn handle_submit_block_impl<S: BuilderApiState, A: BuilderApi<S>>(
7070
// Honor caller q-value preference: pick the highest-priority encoding that
7171
// we can actually produce. Server preference for tiebreaks is SSZ first.
7272
let response_encoding = accept_types.preferred(&[EncodingType::Ssz, EncodingType::Json]);
73-
let accepts_ssz = response_encoding == Some(EncodingType::Ssz);
74-
let accepts_json = response_encoding == Some(EncodingType::Json);
7573

7674
info!(ua, ms_into_slot = now.saturating_sub(slot_start_ms), "new request");
7775

@@ -126,28 +124,29 @@ async fn handle_submit_block_impl<S: BuilderApiState, A: BuilderApi<S>>(
126124
.with_label_values(&["200", SUBMIT_BLINDED_BLOCK_ENDPOINT_TAG])
127125
.inc();
128126

129-
// Try SSZ
130-
if accepts_ssz {
131-
let mut response = payload_and_blobs.data.as_ssz_bytes().into_response();
132-
133-
let content_type_header = EncodingType::Ssz.content_type_header().clone();
134-
response.headers_mut().insert(CONTENT_TYPE, content_type_header);
135-
response.headers_mut().insert(
136-
CONSENSUS_VERSION_HEADER,
137-
HeaderValue::from_str(&payload_and_blobs.version.to_string()).unwrap(),
138-
);
139-
info!("sending response as SSZ");
140-
return Ok(response);
141-
}
142-
143-
// Handle JSON
144-
if accepts_json {
145-
Ok((StatusCode::OK, axum::Json(payload_and_blobs)).into_response())
146-
} else {
147-
// This shouldn't ever happen but the compiler needs it
148-
Err(PbsClientError::DecodeError(
127+
// Three arms: no viable encoding (unreachable in practice —
128+
// `get_accept_types` errors earlier if the caller offers
129+
// nothing we support), SSZ, or JSON.
130+
match response_encoding {
131+
None => Err(PbsClientError::DecodeError(
149132
"no viable accept types in request".to_string(),
150-
))
133+
)),
134+
Some(EncodingType::Ssz) => {
135+
let mut response = payload_and_blobs.data.as_ssz_bytes().into_response();
136+
137+
let content_type_header = EncodingType::Ssz.content_type_header().clone();
138+
response.headers_mut().insert(CONTENT_TYPE, content_type_header);
139+
response.headers_mut().insert(
140+
CONSENSUS_VERSION_HEADER,
141+
HeaderValue::from_str(&payload_and_blobs.version.to_string()).unwrap(),
142+
);
143+
info!("sending response as SSZ");
144+
Ok(response)
145+
}
146+
Some(EncodingType::Json) => {
147+
info!("sending response as JSON");
148+
Ok((StatusCode::OK, axum::Json(payload_and_blobs)).into_response())
149+
}
151150
}
152151
}
153152
},

tests/tests/pbs_get_header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ async fn test_get_header_multitype_json_light() -> Result<()> {
213213
/// requires a non-None rpc_url to start in that mode. A non-existent address is
214214
/// fine; if the parent block fetch fails the relay response is still returned
215215
/// (extra validation is skipped with a warning).
216+
#[allow(clippy::too_many_arguments)]
216217
async fn test_get_header_impl(
217218
accept_types: Vec<EncodingType>,
218219
relay_types: HashSet<EncodingType>,

0 commit comments

Comments
 (0)