mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
add missing fields to get blob sidecars request (#5987)
* add missing fields to get blob sidecars request * add fork versioned response impl * only compute the block root once * Merge branch 'unstable' of https://github.com/sigp/lighthouse into add-missing-fields-get-blob-sidecars * Merge branch 'unstable' of https://github.com/sigp/lighthouse into add-missing-fields-get-blob-sidecars * fetch root first fetch from cache if its a head block * fmt * always load from db
This commit is contained in:
@@ -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,
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -252,23 +255,30 @@ impl BlockId {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the `BlobSidecarList` identified by `self`.
|
||||
pub fn blob_sidecar_list<T: BeaconChainTypes>(
|
||||
&self,
|
||||
chain: &BeaconChain<T>,
|
||||
) -> Result<BlobSidecarList<T::EthSpec>, warp::Rejection> {
|
||||
let root = self.root(chain)?.0;
|
||||
chain
|
||||
.get_blobs(&root)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)
|
||||
}
|
||||
|
||||
pub fn blob_sidecar_list_filtered<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 blob_sidecar_list = self.blob_sidecar_list(chain)?;
|
||||
) -> Result<
|
||||
(
|
||||
SignedBlindedBeaconBlock<T::EthSpec>,
|
||||
BlobSidecarList<T::EthSpec>,
|
||||
ExecutionOptimistic,
|
||||
Finalized,
|
||||
),
|
||||
warp::Rejection,
|
||||
> {
|
||||
let (root, execution_optimistic, finalized) = self.root(chain)?;
|
||||
let block = 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)?;
|
||||
|
||||
let blob_sidecar_list_filtered = match indices.indices {
|
||||
Some(vec) => {
|
||||
let list = blob_sidecar_list
|
||||
@@ -280,7 +290,12 @@ impl BlockId {
|
||||
}
|
||||
None => blob_sidecar_list,
|
||||
};
|
||||
Ok(blob_sidecar_list_filtered)
|
||||
Ok((
|
||||
block,
|
||||
blob_sidecar_list_filtered,
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user