-
Notifications
You must be signed in to change notification settings - Fork 72
Add SSZ to PBS #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SSZ to PBS #372
Changes from 10 commits
3a2c7d5
5059593
35b8542
4acddbe
7005422
06c207f
24fabca
f0875cd
bad5675
50fccb5
86fa858
e7335f6
8c82b84
9a58c07
01f6b04
a287e96
de99bb9
06a3092
a556aa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| use alloy::primitives::utils::format_ether; | ||
| use axum::{ | ||
| extract::{Path, State}, | ||
| http::HeaderMap, | ||
| http::{HeaderMap, HeaderValue}, | ||
| response::IntoResponse, | ||
| }; | ||
| use cb_common::{ | ||
| pbs::GetHeaderParams, | ||
| utils::{get_user_agent, ms_into_slot}, | ||
| pbs::{GetHeaderParams, VersionedResponse}, | ||
| utils::{Accept, CONSENSUS_VERSION_HEADER, get_accept_header, get_user_agent, ms_into_slot}, | ||
| }; | ||
| use reqwest::StatusCode; | ||
| use reqwest::{StatusCode, header::CONTENT_TYPE}; | ||
| use ssz::Encode; | ||
| use tracing::{error, info}; | ||
|
|
||
| use crate::{ | ||
|
|
@@ -32,16 +33,44 @@ pub async fn handle_get_header<S: BuilderApiState, A: BuilderApi<S>>( | |
|
|
||
| let ua = get_user_agent(&req_headers); | ||
| let ms_into_slot = ms_into_slot(params.slot, state.config.chain); | ||
| let accept_header = get_accept_header(&req_headers); | ||
|
|
||
| info!(ua, ms_into_slot, "new request"); | ||
|
|
||
| match A::get_header(params, req_headers, state.clone()).await { | ||
| Ok(res) => { | ||
| if let Some(max_bid) = res { | ||
| info!(value_eth = format_ether(max_bid.value()), block_hash =% max_bid.block_hash(), "received header"); | ||
|
|
||
| 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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about catching an error and resubmitting with a different encoding? i assume that's what the BN does already instead of mapping whether a given sidecar supports what
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a significant rework; so much so that it now lives in its own branch built on top of this one: https://github.com/Commit-Boost/commit-boost-client/tree/ssz-update-v2 |
||
| Accept::Ssz => { | ||
| let mut res = match &max_bid { | ||
| VersionedResponse::Electra(max_bid) => { | ||
| (StatusCode::OK, max_bid.as_ssz_bytes()).into_response() | ||
| } | ||
| }; | ||
| let Ok(consensus_version_header) = HeaderValue::from_str(max_bid.version()) | ||
| else { | ||
| info!("sending response as JSON"); | ||
| return Ok((StatusCode::OK, axum::Json(max_bid)).into_response()); | ||
| }; | ||
| let Ok(content_type_header) = | ||
| HeaderValue::from_str(&format!("{}", Accept::Ssz)) | ||
| else { | ||
| info!("sending response as JSON"); | ||
| return Ok((StatusCode::OK, axum::Json(max_bid)).into_response()); | ||
| }; | ||
| res.headers_mut() | ||
| .insert(CONSENSUS_VERSION_HEADER, consensus_version_header); | ||
| res.headers_mut().insert(CONTENT_TYPE, content_type_header); | ||
| info!("sending response as SSZ"); | ||
| res | ||
| } | ||
| Accept::Json | Accept::Any => { | ||
| (StatusCode::OK, axum::Json(max_bid)).into_response() | ||
| } | ||
| }; | ||
| Ok(response) | ||
| } else { | ||
| // spec: return 204 if request is valid but no bid available | ||
| info!("no header available for slot"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.