Skip to content

Commit f01dc55

Browse files
authored
Update engine_getBlobsV2 response type and add getBlobsV2 tests (#7505)
Update `engine_getBlobsV2` response type to `Option<Vec<BlobsAndProofV2>>`. See recent spec change [here](ethereum/execution-apis#630). Added some tests to cover basic fetch blob scenarios.
1 parent a2797d4 commit f01dc55

File tree

8 files changed

+549
-63
lines changed

8 files changed

+549
-63
lines changed

Cargo.lock

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ maplit = "1"
188188
merkle_proof = { path = "consensus/merkle_proof" }
189189
metrics = { path = "common/metrics" }
190190
milhouse = "0.5"
191+
mockall = "0.13"
192+
mockall_double = "0.3"
191193
mockito = "1.5.0"
192194
monitoring_api = { path = "common/monitoring_api" }
193195
network = { path = "beacon_node/network" }

beacon_node/beacon_chain/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
[package]
23
name = "beacon_chain"
34
version = "0.2.0"
@@ -69,6 +70,8 @@ types = { workspace = true }
6970
[dev-dependencies]
7071
criterion = { workspace = true }
7172
maplit = { workspace = true }
73+
mockall = { workspace = true }
74+
mockall_double = { workspace = true }
7275
serde_json = { workspace = true }
7376

7477
[[bench]]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use crate::blob_verification::{GossipBlobError, GossipVerifiedBlob};
2+
use crate::fetch_blobs::{EngineGetBlobsOutput, FetchEngineBlobError};
3+
use crate::observed_data_sidecars::DoNotObserve;
4+
use crate::{AvailabilityProcessingStatus, BeaconChain, BeaconChainTypes};
5+
use execution_layer::json_structures::{BlobAndProofV1, BlobAndProofV2};
6+
use kzg::Kzg;
7+
#[cfg(test)]
8+
use mockall::automock;
9+
use std::sync::Arc;
10+
use task_executor::TaskExecutor;
11+
use types::{BlobSidecar, ChainSpec, Hash256, Slot};
12+
13+
/// An adapter to the `BeaconChain` functionalities to remove `BeaconChain` from direct dependency to enable testing fetch blobs logic.
14+
pub(crate) struct FetchBlobsBeaconAdapter<T: BeaconChainTypes> {
15+
chain: Arc<BeaconChain<T>>,
16+
spec: Arc<ChainSpec>,
17+
}
18+
19+
#[cfg_attr(test, automock, allow(dead_code))]
20+
impl<T: BeaconChainTypes> FetchBlobsBeaconAdapter<T> {
21+
pub(crate) fn new(chain: Arc<BeaconChain<T>>) -> Self {
22+
let spec = chain.spec.clone();
23+
Self { chain, spec }
24+
}
25+
26+
pub(crate) fn spec(&self) -> &Arc<ChainSpec> {
27+
&self.spec
28+
}
29+
30+
pub(crate) fn kzg(&self) -> &Arc<Kzg> {
31+
&self.chain.kzg
32+
}
33+
34+
pub(crate) fn executor(&self) -> &TaskExecutor {
35+
&self.chain.task_executor
36+
}
37+
38+
pub(crate) async fn get_blobs_v1(
39+
&self,
40+
versioned_hashes: Vec<Hash256>,
41+
) -> Result<Vec<Option<BlobAndProofV1<T::EthSpec>>>, FetchEngineBlobError> {
42+
let execution_layer = self
43+
.chain
44+
.execution_layer
45+
.as_ref()
46+
.ok_or(FetchEngineBlobError::ExecutionLayerMissing)?;
47+
48+
execution_layer
49+
.get_blobs_v1(versioned_hashes)
50+
.await
51+
.map_err(FetchEngineBlobError::RequestFailed)
52+
}
53+
54+
pub(crate) async fn get_blobs_v2(
55+
&self,
56+
versioned_hashes: Vec<Hash256>,
57+
) -> Result<Option<Vec<BlobAndProofV2<T::EthSpec>>>, FetchEngineBlobError> {
58+
let execution_layer = self
59+
.chain
60+
.execution_layer
61+
.as_ref()
62+
.ok_or(FetchEngineBlobError::ExecutionLayerMissing)?;
63+
64+
execution_layer
65+
.get_blobs_v2(versioned_hashes)
66+
.await
67+
.map_err(FetchEngineBlobError::RequestFailed)
68+
}
69+
70+
pub(crate) fn verify_blob_for_gossip(
71+
&self,
72+
blob: &Arc<BlobSidecar<T::EthSpec>>,
73+
) -> Result<GossipVerifiedBlob<T, DoNotObserve>, GossipBlobError> {
74+
GossipVerifiedBlob::<T, DoNotObserve>::new(blob.clone(), blob.index, &self.chain)
75+
}
76+
77+
pub(crate) async fn process_engine_blobs(
78+
&self,
79+
slot: Slot,
80+
block_root: Hash256,
81+
blobs: EngineGetBlobsOutput<T::EthSpec>,
82+
) -> Result<AvailabilityProcessingStatus, FetchEngineBlobError> {
83+
self.chain
84+
.process_engine_blobs(slot, block_root, blobs)
85+
.await
86+
.map_err(FetchEngineBlobError::BlobProcessingError)
87+
}
88+
89+
pub(crate) fn fork_choice_contains_block(&self, block_root: &Hash256) -> bool {
90+
self.chain
91+
.canonical_head
92+
.fork_choice_read_lock()
93+
.contains_block(block_root)
94+
}
95+
}

0 commit comments

Comments
 (0)