Skip to content

Ensure light_client/updates endpoint returns spec compliant SSZ data #7230

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

Merged
merged 7 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions beacon_node/http_api/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::version::{
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::types::{
self as api_types, ChainSpec, ForkVersionedResponse, LightClientUpdate,
LightClientUpdateResponseChunk, LightClientUpdateSszResponse, LightClientUpdatesQuery,
LightClientUpdateResponseChunk, LightClientUpdateResponseChunkInner, LightClientUpdatesQuery,
};
use ssz::Encode;
use std::sync::Arc;
Expand Down Expand Up @@ -37,15 +37,9 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
.map(|update| map_light_client_update_to_ssz_chunk::<T>(&chain, update))
.collect::<Vec<LightClientUpdateResponseChunk>>();

let ssz_response = LightClientUpdateSszResponse {
response_chunk_len: (light_client_updates.len() as u64).to_le_bytes().to_vec(),
response_chunk: response_chunks.as_ssz_bytes(),
}
.as_ssz_bytes();

Response::builder()
.status(200)
.body(ssz_response)
.body(response_chunks.as_ssz_bytes())
.map(|res: Response<Vec<u8>>| add_ssz_content_type_header(res))
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
Expand Down Expand Up @@ -159,16 +153,24 @@ fn map_light_client_update_to_ssz_chunk<T: BeaconChainTypes>(
) -> LightClientUpdateResponseChunk {
let fork_name = chain
.spec
.fork_name_at_slot::<T::EthSpec>(*light_client_update.signature_slot());
.fork_name_at_slot::<T::EthSpec>(light_client_update.attested_header_slot());

let fork_digest = ChainSpec::compute_fork_digest(
chain.spec.fork_version_for_name(fork_name),
chain.genesis_validators_root,
);

LightClientUpdateResponseChunk {
let payload = light_client_update.as_ssz_bytes();
let response_chunk_len = fork_digest.len() + payload.len();

let response_chunk = LightClientUpdateResponseChunkInner {
context: fork_digest,
payload: light_client_update.as_ssz_bytes(),
payload,
};

LightClientUpdateResponseChunk {
response_chunk_len: response_chunk_len as u64,
response_chunk,
}
}

Expand Down
8 changes: 4 additions & 4 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,13 @@ pub struct LightClientUpdatesQuery {
}

#[derive(Encode, Decode)]
pub struct LightClientUpdateSszResponse {
pub response_chunk_len: Vec<u8>,
pub response_chunk: Vec<u8>,
pub struct LightClientUpdateResponseChunk {
pub response_chunk_len: u64,
pub response_chunk: LightClientUpdateResponseChunkInner,
}

#[derive(Encode, Decode)]
pub struct LightClientUpdateResponseChunk {
pub struct LightClientUpdateResponseChunkInner {
pub context: [u8; 4],
pub payload: Vec<u8>,
}
Expand Down