From f1f04bc68a5506c839693d25bc8c626c48ec8669 Mon Sep 17 00:00:00 2001 From: Gua00va <105484243+Gua00va@users.noreply.github.com> Date: Fri, 21 Jul 2023 20:26:57 +0530 Subject: [PATCH] Add Changes to BlobSidecars Endpoint (#4455) * changed name * Fix sidecars * Added query type and parrameter * added query struct and function * added method * improved filtering method * added blob_sidecar_list_indexed to block_id * minor blobqueryindex fix * function and formatting fix * minor function and naming fix * minor changes --- beacon_node/http_api/src/block_id.rs | 21 +++++++++++++++++++++ beacon_node/http_api/src/lib.rs | 10 ++++++---- common/eth2/src/types.rs | 7 +++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/beacon_node/http_api/src/block_id.rs b/beacon_node/http_api/src/block_id.rs index d5f6ac886..1a3d852da 100644 --- a/beacon_node/http_api/src/block_id.rs +++ b/beacon_node/http_api/src/block_id.rs @@ -1,5 +1,6 @@ use crate::{state_id::checkpoint_slot_and_execution_optimistic, ExecutionOptimistic}; use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes, WhenSlotSkipped}; +use eth2::types::BlobIndicesQuery; use eth2::types::BlockId as CoreBlockId; use std::fmt; use std::str::FromStr; @@ -266,6 +267,26 @@ impl BlockId { Err(e) => Err(warp_utils::reject::beacon_chain_error(e)), } } + + pub async fn blob_sidecar_list_filtered( + &self, + indices: BlobIndicesQuery, + chain: &BeaconChain, + ) -> Result, warp::Rejection> { + let blob_sidecar_list = self.blob_sidecar_list(&chain).await?; + let blob_sidecar_list_filtered = match indices.indices { + Some(vec) => { + let list = blob_sidecar_list + .into_iter() + .filter(|blob_sidecar| vec.contains(&blob_sidecar.index)) + .collect(); + BlobSidecarList::new(list) + .map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e)))? + } + None => blob_sidecar_list, + }; + Ok(blob_sidecar_list_filtered) + } } impl FromStr for BlockId { diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 6707719ae..c9b6af0a4 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -1487,21 +1487,23 @@ pub fn serve( .and(warp::path("beacon")) .and(warp::path("blob_sidecars")) .and(block_id_or_err) + .and(warp::query::()) .and(warp::path::end()) .and(chain_filter.clone()) .and(warp::header::optional::("accept")) .and_then( |block_id: BlockId, + indices: api_types::BlobIndicesQuery, chain: Arc>, accept_header: Option| { async move { - let blob_sidecar_list = block_id.blob_sidecar_list(&chain).await?; - + let blob_sidecar_list_filtered = + block_id.blob_sidecar_list_filtered(indices, &chain).await?; match accept_header { Some(api_types::Accept::Ssz) => Response::builder() .status(200) .header("Content-Type", "application/octet-stream") - .body(blob_sidecar_list.as_ssz_bytes().into()) + .body(blob_sidecar_list_filtered.as_ssz_bytes().into()) .map_err(|e| { warp_utils::reject::custom_server_error(format!( "failed to create response: {}", @@ -1509,7 +1511,7 @@ pub fn serve( )) }), _ => Ok(warp::reply::json(&api_types::GenericResponse::from( - blob_sidecar_list, + blob_sidecar_list_filtered, )) .into_response()), } diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 7bb43d8a9..29eb0ac61 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -648,6 +648,13 @@ pub struct ValidatorBalancesQuery { pub id: Option>, } +#[derive(Clone, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct BlobIndicesQuery { + #[serde(default, deserialize_with = "option_query_vec")] + pub indices: Option>, +} + #[derive(Clone, Serialize, Deserialize)] #[serde(transparent)] pub struct ValidatorIndexData(#[serde(with = "serde_utils::quoted_u64_vec")] pub Vec);