Skip to content
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

add missing fields to get blob sidecars request #5987

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
108 changes: 66 additions & 42 deletions beacon_node/http_api/src/block_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ impl BlockId {
}
}

pub fn blinded_block_by_root<T: BeaconChainTypes>(
root: &Hash256,
chain: &BeaconChain<T>,
) -> Result<Option<SignedBlindedBeaconBlock<T::EthSpec>>, warp::Rejection> {
chain
.get_blinded_block(root)
.map_err(warp_utils::reject::beacon_chain_error)
}

/// Return the `SignedBeaconBlock` identified by `self`.
pub fn blinded_block<T: BeaconChainTypes>(
&self,
Expand All @@ -149,38 +158,32 @@ impl BlockId {
}
CoreBlockId::Slot(slot) => {
let (root, execution_optimistic, finalized) = self.root(chain)?;
chain
.get_blinded_block(&root)
.map_err(warp_utils::reject::beacon_chain_error)
.and_then(|block_opt| match block_opt {
Some(block) => {
if block.slot() != *slot {
return Err(warp_utils::reject::custom_not_found(format!(
"slot {} was skipped",
slot
)));
}
Ok((block, execution_optimistic, finalized))
BlockId::blinded_block_by_root(&root, chain).and_then(|block_opt| match block_opt {
Some(block) => {
if block.slot() != *slot {
return Err(warp_utils::reject::custom_not_found(format!(
"slot {} was skipped",
slot
)));
}
None => Err(warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
root
))),
})
Ok((block, execution_optimistic, finalized))
}
None => Err(warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
root
))),
})
}
_ => {
let (root, execution_optimistic, finalized) = self.root(chain)?;
let block = chain
.get_blinded_block(&root)
.map_err(warp_utils::reject::beacon_chain_error)
.and_then(|root_opt| {
root_opt.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
root
))
})
})?;
let block = BlockId::blinded_block_by_root(&root, chain).and_then(|root_opt| {
root_opt.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"beacon block with root {}",
root
))
})
})?;
Ok((block, execution_optimistic, finalized))
}
}
Expand Down Expand Up @@ -252,23 +255,39 @@ impl BlockId {
}
}

/// Return the `BlobSidecarList` identified by `self`.
pub fn blob_sidecar_list<T: BeaconChainTypes>(
#[allow(clippy::type_complexity)]
pub fn get_blinded_block_and_blob_list_filtered<T: BeaconChainTypes>(
&self,
indices: BlobIndicesQuery,
chain: &BeaconChain<T>,
) -> Result<BlobSidecarList<T::EthSpec>, warp::Rejection> {
let root = self.root(chain)?.0;
chain
) -> Result<
(
SignedBlindedBeaconBlock<T::EthSpec>,
BlobSidecarList<T::EthSpec>,
ExecutionOptimistic,
Finalized,
),
warp::Rejection,
> {
let (root, execution_optimistic, finalized) = self.root(chain)?;
let block = match &self.0 {
CoreBlockId::Head => {
let (cached_head, _) = chain
.canonical_head
.head_and_execution_status()
.map_err(warp_utils::reject::beacon_chain_error)?;
cached_head.snapshot.beacon_block.clone_as_blinded()
}
michaelsproul marked this conversation as resolved.
Show resolved Hide resolved
_ => BlockId::blinded_block_by_root(&root, chain)?.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!("beacon block with root {}", root))
})?,
};

// Return the `BlobSidecarList` identified by `self`.
let blob_sidecar_list = chain
.get_blobs(&root)
.map_err(warp_utils::reject::beacon_chain_error)
}
.map_err(warp_utils::reject::beacon_chain_error)?;

pub fn blob_sidecar_list_filtered<T: BeaconChainTypes>(
&self,
indices: BlobIndicesQuery,
chain: &BeaconChain<T>,
) -> Result<BlobSidecarList<T::EthSpec>, warp::Rejection> {
let blob_sidecar_list = self.blob_sidecar_list(chain)?;
let blob_sidecar_list_filtered = match indices.indices {
Some(vec) => {
let list = blob_sidecar_list
Expand All @@ -280,7 +299,12 @@ impl BlockId {
}
None => blob_sidecar_list,
};
Ok(blob_sidecar_list_filtered)
Ok((
block,
blob_sidecar_list_filtered,
execution_optimistic,
finalized,
))
}
}

Expand Down
24 changes: 18 additions & 6 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,8 +1734,12 @@ pub fn serve<T: BeaconChainTypes>(
accept_header: Option<api_types::Accept>| {
task_spawner.blocking_response_task(Priority::P1, move || {
let indices = indices_res?;
let blob_sidecar_list_filtered =
block_id.blob_sidecar_list_filtered(indices, &chain)?;
let (block, blob_sidecar_list_filtered, execution_optimistic, finalized) =
block_id.get_blinded_block_and_blob_list_filtered(indices, &chain)?;
let fork_name = block
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;

match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
.status(200)
Expand All @@ -1747,11 +1751,19 @@ pub fn serve<T: BeaconChainTypes>(
e
))
}),
_ => Ok(warp::reply::json(&api_types::GenericResponse::from(
blob_sidecar_list_filtered,
))
.into_response()),
_ => {
// Post as a V2 endpoint so we return the fork version.
let res = execution_optimistic_finalized_fork_versioned_response(
V2,
fork_name,
execution_optimistic,
finalized,
&blob_sidecar_list_filtered,
)?;
Ok(warp::reply::json(&res).into_response())
}
}
.map(|resp| add_consensus_version_header(resp, fork_name))
})
},
);
Expand Down
3 changes: 2 additions & 1 deletion common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,8 @@ impl BeaconNodeHttpClient {
&self,
block_id: BlockId,
indices: Option<&[u64]>,
) -> Result<Option<GenericResponse<BlobSidecarList<E>>>, Error> {
) -> Result<Option<ExecutionOptimisticFinalizedForkVersionedResponse<BlobSidecarList<E>>>, Error>
{
let mut path = self.get_blobs_path(block_id)?;
if let Some(indices) = indices {
let indices_string = indices
Expand Down
12 changes: 11 additions & 1 deletion consensus/types/src/blob_sidecar.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::test_utils::TestRandom;
use crate::ForkName;
use crate::{
beacon_block_body::BLOB_KZG_COMMITMENTS_INDEX, BeaconBlockHeader, BeaconStateError, Blob,
Epoch, EthSpec, FixedVector, Hash256, SignedBeaconBlockHeader, Slot, VariableList,
};
use crate::{KzgProofs, SignedBeaconBlock};
use crate::{ForkVersionDeserialize, KzgProofs, SignedBeaconBlock};
use bls::Signature;
use derivative::Derivative;
use kzg::{Blob as KzgBlob, Kzg, KzgCommitment, KzgProof, BYTES_PER_BLOB, BYTES_PER_FIELD_ELEMENT};
Expand Down Expand Up @@ -273,3 +274,12 @@ pub type BlobSidecarList<E> = VariableList<Arc<BlobSidecar<E>>, <E as EthSpec>::
pub type FixedBlobSidecarList<E> =
FixedVector<Option<Arc<BlobSidecar<E>>>, <E as EthSpec>::MaxBlobsPerBlock>;
pub type BlobsList<E> = VariableList<Blob<E>, <E as EthSpec>::MaxBlobCommitmentsPerBlock>;

impl<E: EthSpec> ForkVersionDeserialize for BlobSidecarList<E> {
fn deserialize_by_fork<'de, D: serde::Deserializer<'de>>(
value: serde_json::value::Value,
_: ForkName,
) -> Result<Self, D::Error> {
serde_json::from_value::<BlobSidecarList<E>>(value).map_err(serde::de::Error::custom)
}
}