Skip to content

Conversation

jclapis
Copy link
Collaborator

@jclapis jclapis commented Sep 9, 2025

This is a modernization of #252 since that's been dormant for a while, but was re-raised in #364. Just about everything was ported over cleanly.

@jclapis jclapis requested a review from ltitanb September 9, 2025 20:38
@jclapis jclapis self-assigned this Sep 9, 2025
@jclapis jclapis added the pbs Pbs module / Builder API label Sep 9, 2025
Copy link
Collaborator

@ltitanb ltitanb left a comment

Choose a reason for hiding this comment

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

We should ideally also test this with kurtosis


/// Parse CONSENSUS_VERSION header
pub fn get_consensus_version_header(req_headers: &HeaderMap) -> Option<ForkName> {
ForkName::from_str(
Copy link
Collaborator

Choose a reason for hiding this comment

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

woth double checking this is not case sensitive

Copy link
Collaborator

Choose a reason for hiding this comment

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

just realized we have our own ForkName, we could also import it from lighthouse

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For case sensitivity, it's defined the way the spec defines it (https://github.com/ethereum/beacon-APIs/blob/672e03e25ace85a3bacaea553fbf374f4f844435/apis/beacon/blocks/blocks.yaml#L21) but Rust will convert everything to lower case regardless.

For ForkName, done in 86fa858.

}
}

impl FromStr for Accept {
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be easier to use crate for this for easier maintainability? eg https://github.com/bltavares/axum-content-negotiation or https://docs.rs/headers-accept/latest/headers_accept/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in e7335f6.


#[must_use]
#[derive(Debug, Clone, Copy, Default)]
pub struct JsonOrSsz<T>(pub T);
Copy link
Collaborator

Choose a reason for hiding this comment

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

thinking about what we'll have to do with: #326, i 'd rather just do this in a function and use a simple "Bytes" extractor on the axum body. Can just pass headers and body and get back T

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, refactored a bunch of the setup in e7335f6 to provide exactly this.


BEACON_NODE_STATUS.with_label_values(&["200", GET_HEADER_ENDPOINT_TAG]).inc();
Ok((StatusCode::OK, axum::Json(max_bid)).into_response())
let response = match accept_header {
Copy link
Collaborator

Choose a reason for hiding this comment

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

here we just asssume the relay just support both? probably fine but ok double checking

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do, if we want to add support for relays that only allow JSON for example, we'll have to probably figure that out on startup and flag them accordingly so we don't ping them to negotiate encoding with every request (assuming they never change it down the line). Do we have stats on how many support SSZ and how many don't?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pbs Pbs module / Builder API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants