Update get blobs endpoint to return a list of BlobSidecars (#4109)

* Update get blobs endpoint to return BlobSidecarList

* Update code comment

* Update blob retrieval to return BlobSidecarList without Arc

* Remove usage of BlobSidecarList type alias to avoid code conflicts

* Add clippy allow exception
This commit is contained in:
Jimmy Chen
2023-03-22 01:56:32 +11:00
committed by GitHub
parent 78414333a2
commit b40dceaae9
4 changed files with 77 additions and 55 deletions

View File

@@ -1293,6 +1293,45 @@ pub fn serve<T: BeaconChainTypes>(
},
);
/*
* beacon/blobs
*/
// GET beacon/blobs/{block_id}
let get_blobs = eth_v1
.and(warp::path("beacon"))
.and(warp::path("blobs"))
.and(block_id_or_err)
.and(warp::path::end())
.and(chain_filter.clone())
.and(warp::header::optional::<api_types::Accept>("accept"))
.and_then(
|block_id: BlockId,
chain: Arc<BeaconChain<T>>,
accept_header: Option<api_types::Accept>| {
async move {
let blob_sidecar_list = block_id.blob_sidecar_list(&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())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
e
))
}),
_ => Ok(warp::reply::json(&api_types::GenericResponse::from(
blob_sidecar_list,
))
.into_response()),
}
}
},
);
/*
* beacon/pool
*/
@@ -3498,41 +3537,6 @@ pub fn serve<T: BeaconChainTypes>(
)
});
// GET lighthouse/beacon/blobs_sidecars/{block_id}
let get_lighthouse_blobs_sidecars = warp::path("lighthouse")
.and(warp::path("beacon"))
.and(warp::path("blobs_sidecars"))
.and(block_id_or_err)
.and(warp::path::end())
.and(chain_filter.clone())
.and(warp::header::optional::<api_types::Accept>("accept"))
.and_then(
|block_id: BlockId,
chain: Arc<BeaconChain<T>>,
accept_header: Option<api_types::Accept>| {
async move {
let blobs_sidecar = block_id.blobs_sidecar(&chain).await?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
.status(200)
.header("Content-Type", "application/octet-stream")
.body(blobs_sidecar.as_ssz_bytes().into())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"failed to create response: {}",
e
))
}),
_ => Ok(warp::reply::json(&api_types::GenericResponse::from(
blobs_sidecar,
))
.into_response()),
}
}
},
);
let get_events = eth_v1
.and(warp::path("events"))
.and(warp::path::end())
@@ -3627,6 +3631,7 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_beacon_block_attestations)
.uor(get_beacon_blinded_block)
.uor(get_beacon_block_root)
.uor(get_blobs)
.uor(get_beacon_pool_attestations)
.uor(get_beacon_pool_attester_slashings)
.uor(get_beacon_pool_proposer_slashings)
@@ -3672,7 +3677,6 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_lighthouse_attestation_performance)
.uor(get_lighthouse_block_packing_efficiency)
.uor(get_lighthouse_merge_readiness)
.uor(get_lighthouse_blobs_sidecars.boxed())
.uor(get_events)
.recover(warp_utils::reject::handle_rejection),
)