Skip to content

Add SSZ types, content negotiation, and encoding helpers#466

Open
JasonVranek wants to merge 1 commit into
mainfrom
pr/ssz-core
Open

Add SSZ types, content negotiation, and encoding helpers#466
JasonVranek wants to merge 1 commit into
mainfrom
pr/ssz-core

Conversation

@JasonVranek
Copy link
Copy Markdown
Collaborator

Summary

Introduces the types and helpers needed for SSZ support in the PBS pipeline. No behavior changes, just plumbing the follow-up PRs build on.

What's in this PR

  • EncodingType enum with FromStr/Display, including MIME parameter tolerance (RFC 7231 §3.1.1.1)
  • AcceptedEncodings with q-value-aware Accept header parsing (RFC 9110 §12.5.1)
  • Content-type and consensus-version header helpers
  • SSZ bid value extraction from SignedBuilderBid for all supported forks (Bellatrix through Fulu)
  • deserialize_body and parse_response_encoding_and_fork helpers
  • Per-fork type aliases for BuilderBid and ExecutionPayloadHeader
  • SszValueError, PbsError::GeneralRequest, PbsClientError::DecodeError/RelayError
  • New workspace deps: headers-accept, mediatype
  • Comprehensive unit tests for all new types and helpers

Review notes

Part 1 of 4: SSZ types → get_header → submit_block → validation bypassing

Attribution

This work builds on the SSZ builder flow originally implemented by @eserilev
in #252 and ported to the current codebase by @jclapis in #403.

Co-authored-by: Eitan Seri-Levi eserilev@ucsc.edu
Co-authored-by: Joe Clapis jclapis@outlook.com

Introduce EncodingType, AcceptedEncodings, and content negotiation
primitives for SSZ support in the PBS pipeline. Includes:

- EncodingType enum with FromStr/Display and MIME param tolerance
- AcceptedEncodings with q-value aware Accept header parsing
- SSZ bid value extraction from SignedBuilderBid by fork
- deserialize_body and parse_response_encoding_and_fork helpers
- Per-fork type aliases for BuilderBid and ExecutionPayloadHeader
- SszValueError, PbsError::GeneralRequest, PbsClientError variants
- Comprehensive unit tests for all new types and helpers
- New deps: headers-accept, mediatype
@JasonVranek JasonVranek requested a review from a team May 20, 2026 00:04
Comment on lines +585 to +586
/// Pick the caller's highest-preference encoding that the server supports.
/// Returns `None` if no overlap exists.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant comment

/// dedup the accepted set is at most one primary plus one optional fallback.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AcceptedEncodings {
/// Caller's highest-preference encoding.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant?

Comment on lines +695 to +696
/// Parse CONTENT TYPE header to get the encoding type of the body, defaulting
/// to JSON if missing or malformed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant?

.unwrap_or(EncodingType::Json)
}

/// Parse CONSENSUS_VERSION header
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Comment on lines +809 to +822
impl Display for BodyDeserializeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BodyDeserializeError::SerdeJsonError(e) => write!(f, "JSON deserialization error: {e}"),
BodyDeserializeError::SszDecodeError(e) => {
write!(f, "SSZ deserialization error: {e:?}")
}
BodyDeserializeError::UnsupportedMediaType => write!(f, "unsupported media type"),
BodyDeserializeError::MissingVersionHeader => {
write!(f, "missing consensus version header")
}
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use thiserror, already a dependency

Comment thread crates/pbs/src/error.rs
NoPayload,
Internal,
DecodeError(String),
#[allow(dead_code)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Comment on lines +125 to +131
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}"))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not bundle these under "GeneralRequest" with a string error message inside, could be an SszError maybe?
and you could derive it from this SszValueError instead of implementing a custom From using thiserror

}
}

pub async fn deserialize_body(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why async?

}

// Get the offset of the message in a SignedBuilderBid SSZ structure
fn get_ssz_value_offset_for_fork(fork: ForkName) -> Option<usize> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None -> SszValueError::UnsupportedFork { name: fork.to_string() }

step as f32 / 10.0
}

/// Format a single `Accept` header entry as `"<media-type>;q=<x.x>"`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[inline]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants