Skip to content

Commit ef8ec35

Browse files
authored
Ensure light_client/updates endpoint returns spec compliant SSZ data (#7230)
Closes #7167 - Ensure the fork digest is generated from ther light client updates attested header and not the signature slot - Ensure the format of the SSZ response is spec compliant
1 parent 9304a59 commit ef8ec35

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

beacon_node/http_api/src/light_client.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::version::{
44
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
55
use eth2::types::{
66
self as api_types, ChainSpec, ForkVersionedResponse, LightClientUpdate,
7-
LightClientUpdateResponseChunk, LightClientUpdateSszResponse, LightClientUpdatesQuery,
7+
LightClientUpdateResponseChunk, LightClientUpdateResponseChunkInner, LightClientUpdatesQuery,
88
};
99
use ssz::Encode;
1010
use std::sync::Arc;
@@ -37,15 +37,9 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
3737
.map(|update| map_light_client_update_to_ssz_chunk::<T>(&chain, update))
3838
.collect::<Vec<LightClientUpdateResponseChunk>>();
3939

40-
let ssz_response = LightClientUpdateSszResponse {
41-
response_chunk_len: (light_client_updates.len() as u64).to_le_bytes().to_vec(),
42-
response_chunk: response_chunks.as_ssz_bytes(),
43-
}
44-
.as_ssz_bytes();
45-
4640
Response::builder()
4741
.status(200)
48-
.body(ssz_response)
42+
.body(response_chunks.as_ssz_bytes())
4943
.map(|res: Response<Vec<u8>>| add_ssz_content_type_header(res))
5044
.map_err(|e| {
5145
warp_utils::reject::custom_server_error(format!(
@@ -159,16 +153,24 @@ fn map_light_client_update_to_ssz_chunk<T: BeaconChainTypes>(
159153
) -> LightClientUpdateResponseChunk {
160154
let fork_name = chain
161155
.spec
162-
.fork_name_at_slot::<T::EthSpec>(*light_client_update.signature_slot());
156+
.fork_name_at_slot::<T::EthSpec>(light_client_update.attested_header_slot());
163157

164158
let fork_digest = ChainSpec::compute_fork_digest(
165159
chain.spec.fork_version_for_name(fork_name),
166160
chain.genesis_validators_root,
167161
);
168162

169-
LightClientUpdateResponseChunk {
163+
let payload = light_client_update.as_ssz_bytes();
164+
let response_chunk_len = fork_digest.len() + payload.len();
165+
166+
let response_chunk = LightClientUpdateResponseChunkInner {
170167
context: fork_digest,
171-
payload: light_client_update.as_ssz_bytes(),
168+
payload,
169+
};
170+
171+
LightClientUpdateResponseChunk {
172+
response_chunk_len: response_chunk_len as u64,
173+
response_chunk,
172174
}
173175
}
174176

common/eth2/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,13 @@ pub struct LightClientUpdatesQuery {
802802
}
803803

804804
#[derive(Encode, Decode)]
805-
pub struct LightClientUpdateSszResponse {
806-
pub response_chunk_len: Vec<u8>,
807-
pub response_chunk: Vec<u8>,
805+
pub struct LightClientUpdateResponseChunk {
806+
pub response_chunk_len: u64,
807+
pub response_chunk: LightClientUpdateResponseChunkInner,
808808
}
809809

810810
#[derive(Encode, Decode)]
811-
pub struct LightClientUpdateResponseChunk {
811+
pub struct LightClientUpdateResponseChunkInner {
812812
pub context: [u8; 4],
813813
pub payload: Vec<u8>,
814814
}

0 commit comments

Comments
 (0)