Fix indices filter in blobs_sidecar http endpoint (#5118)
* add get blobs unit test * Use a multi_key_query for blob_sidecar indices * Fix test * Remove env_logger --------- Co-authored-by: realbigsean <seananderson33@GMAIL.com>
This commit is contained in:
parent
1cebf41452
commit
b55b58b3c6
@ -1704,18 +1704,19 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(warp::path("beacon"))
|
.and(warp::path("beacon"))
|
||||||
.and(warp::path("blob_sidecars"))
|
.and(warp::path("blob_sidecars"))
|
||||||
.and(block_id_or_err)
|
.and(block_id_or_err)
|
||||||
.and(warp::query::<api_types::BlobIndicesQuery>())
|
|
||||||
.and(warp::path::end())
|
.and(warp::path::end())
|
||||||
|
.and(multi_key_query::<api_types::BlobIndicesQuery>())
|
||||||
.and(task_spawner_filter.clone())
|
.and(task_spawner_filter.clone())
|
||||||
.and(chain_filter.clone())
|
.and(chain_filter.clone())
|
||||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||||
.then(
|
.then(
|
||||||
|block_id: BlockId,
|
|block_id: BlockId,
|
||||||
indices: api_types::BlobIndicesQuery,
|
indices_res: Result<api_types::BlobIndicesQuery, warp::Rejection>,
|
||||||
task_spawner: TaskSpawner<T::EthSpec>,
|
task_spawner: TaskSpawner<T::EthSpec>,
|
||||||
chain: Arc<BeaconChain<T>>,
|
chain: Arc<BeaconChain<T>>,
|
||||||
accept_header: Option<api_types::Accept>| {
|
accept_header: Option<api_types::Accept>| {
|
||||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||||
|
let indices = indices_res?;
|
||||||
let blob_sidecar_list_filtered =
|
let blob_sidecar_list_filtered =
|
||||||
block_id.blob_sidecar_list_filtered(indices, &chain)?;
|
block_id.blob_sidecar_list_filtered(indices, &chain)?;
|
||||||
match accept_header {
|
match accept_header {
|
||||||
|
@ -1587,6 +1587,39 @@ impl ApiTester {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn test_get_blob_sidecars(self, use_indices: bool) -> Self {
|
||||||
|
let block_id = BlockId(CoreBlockId::Finalized);
|
||||||
|
let (block_root, _, _) = block_id.root(&self.chain).unwrap();
|
||||||
|
let (block, _, _) = block_id.full_block(&self.chain).await.unwrap();
|
||||||
|
let num_blobs = block.num_expected_blobs();
|
||||||
|
let blob_indices = if use_indices {
|
||||||
|
Some(
|
||||||
|
(0..num_blobs.saturating_sub(1) as u64)
|
||||||
|
.into_iter()
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let result = match self
|
||||||
|
.client
|
||||||
|
.get_blobs::<E>(CoreBlockId::Root(block_root), blob_indices.as_deref())
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(result) => result.unwrap().data,
|
||||||
|
Err(e) => panic!("query failed incorrectly: {e:?}"),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
result.len(),
|
||||||
|
blob_indices.map_or(num_blobs, |indices| indices.len())
|
||||||
|
);
|
||||||
|
let expected = block.slot();
|
||||||
|
assert_eq!(result.get(0).unwrap().slot(), expected);
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn test_beacon_blocks_attestations(self) -> Self {
|
pub async fn test_beacon_blocks_attestations(self) -> Self {
|
||||||
for block_id in self.interesting_block_ids() {
|
for block_id in self.interesting_block_ids() {
|
||||||
let result = self
|
let result = self
|
||||||
@ -6291,6 +6324,27 @@ async fn builder_works_post_deneb() {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn get_blob_sidecars() {
|
||||||
|
let mut config = ApiTesterConfig {
|
||||||
|
retain_historic_states: false,
|
||||||
|
spec: E::default_spec(),
|
||||||
|
};
|
||||||
|
config.spec.altair_fork_epoch = Some(Epoch::new(0));
|
||||||
|
config.spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||||
|
config.spec.capella_fork_epoch = Some(Epoch::new(0));
|
||||||
|
config.spec.deneb_fork_epoch = Some(Epoch::new(0));
|
||||||
|
|
||||||
|
ApiTester::new_from_config(config)
|
||||||
|
.await
|
||||||
|
.test_post_beacon_blocks_valid()
|
||||||
|
.await
|
||||||
|
.test_get_blob_sidecars(false)
|
||||||
|
.await
|
||||||
|
.test_get_blob_sidecars(true)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn post_validator_liveness_epoch() {
|
async fn post_validator_liveness_epoch() {
|
||||||
ApiTester::new()
|
ApiTester::new()
|
||||||
|
@ -1064,8 +1064,18 @@ impl BeaconNodeHttpClient {
|
|||||||
pub async fn get_blobs<T: EthSpec>(
|
pub async fn get_blobs<T: EthSpec>(
|
||||||
&self,
|
&self,
|
||||||
block_id: BlockId,
|
block_id: BlockId,
|
||||||
|
indices: Option<&[u64]>,
|
||||||
) -> Result<Option<GenericResponse<BlobSidecarList<T>>>, Error> {
|
) -> Result<Option<GenericResponse<BlobSidecarList<T>>>, Error> {
|
||||||
let path = self.get_blobs_path(block_id)?;
|
let mut path = self.get_blobs_path(block_id)?;
|
||||||
|
if let Some(indices) = indices {
|
||||||
|
let indices_string = indices
|
||||||
|
.iter()
|
||||||
|
.map(|i| i.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(",");
|
||||||
|
path.query_pairs_mut()
|
||||||
|
.append_pair("indices", &indices_string);
|
||||||
|
}
|
||||||
let Some(response) = self.get_response(path, |b| b).await.optional()? else {
|
let Some(response) = self.get_response(path, |b| b).await.optional()? else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user