Skip to content

Commit 7b8cb0d

Browse files
committed
impl get_blobs_v2 fallback
1 parent ad85059 commit 7b8cb0d

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

beacon_node/beacon_chain/src/fetch_blobs/fetch_blobs_beacon_adapter.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl<T: BeaconChainTypes> FetchBlobsBeaconAdapter<T> {
5151
.map_err(FetchEngineBlobError::RequestFailed)
5252
}
5353

54-
// TODO(dknopik): fall back to this
5554
pub(crate) async fn get_blobs_v2(
5655
&self,
5756
versioned_hashes: Vec<Hash256>,
@@ -138,4 +137,18 @@ impl<T: BeaconChainTypes> FetchBlobsBeaconAdapter<T> {
138137
.fork_choice_read_lock()
139138
.contains_block(block_root)
140139
}
140+
141+
pub(crate) async fn supports_get_blobs_v3(&self) -> Result<bool, FetchEngineBlobError> {
142+
let execution_layer = self
143+
.chain
144+
.execution_layer
145+
.as_ref()
146+
.ok_or(FetchEngineBlobError::ExecutionLayerMissing)?;
147+
148+
execution_layer
149+
.get_engine_capabilities(None)
150+
.await
151+
.map_err(FetchEngineBlobError::RequestFailed)
152+
.map(|caps| caps.get_blobs_v3)
153+
}
141154
}

beacon_node/beacon_chain/src/fetch_blobs/mod.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async fn fetch_and_process_engine_blobs_inner<T: BeaconChainTypes>(
124124
.spec()
125125
.is_peer_das_enabled_for_epoch(block.epoch())
126126
{
127-
fetch_and_process_blobs_v2(
127+
fetch_and_process_blobs_v2_or_v3(
128128
chain_adapter,
129129
block_root,
130130
block,
@@ -239,7 +239,7 @@ async fn fetch_and_process_blobs_v1<T: BeaconChainTypes>(
239239
}
240240

241241
#[instrument(skip_all, level = "debug")]
242-
async fn fetch_and_process_blobs_v2<T: BeaconChainTypes>(
242+
async fn fetch_and_process_blobs_v2_or_v3<T: BeaconChainTypes>(
243243
chain_adapter: FetchBlobsBeaconAdapter<T>,
244244
block_root: Hash256,
245245
block: Arc<SignedBeaconBlock<T::EthSpec>>,
@@ -250,14 +250,25 @@ async fn fetch_and_process_blobs_v2<T: BeaconChainTypes>(
250250
let num_expected_blobs = versioned_hashes.len();
251251

252252
metrics::observe(&metrics::BLOBS_FROM_EL_EXPECTED, num_expected_blobs as f64);
253-
// TODO(dknopik): implement fallback to get_blobs_v2
254-
debug!(num_expected_blobs, "Fetching blobs from the EL");
255-
let response = chain_adapter
256-
.get_blobs_v3(versioned_hashes)
257-
.await
258-
.inspect_err(|_| {
259-
inc_counter(&metrics::BLOBS_FROM_EL_ERROR_TOTAL);
260-
})?;
253+
254+
let response = if chain_adapter.supports_get_blobs_v3().await? {
255+
debug!(num_expected_blobs, "Fetching available blobs from the EL");
256+
chain_adapter
257+
.get_blobs_v3(versioned_hashes)
258+
.await
259+
.inspect_err(|_| {
260+
inc_counter(&metrics::BLOBS_FROM_EL_ERROR_TOTAL);
261+
})?
262+
} else {
263+
debug!(num_expected_blobs, "Fetching all blobs from the EL");
264+
chain_adapter
265+
.get_blobs_v2(versioned_hashes)
266+
.await
267+
.inspect_err(|_| {
268+
inc_counter(&metrics::BLOBS_FROM_EL_ERROR_TOTAL);
269+
})?
270+
.map(|vec| vec.into_iter().map(Some).collect())
271+
};
261272

262273
let Some(blobs_and_proofs) = response else {
263274
debug!(num_expected_blobs, "No blobs fetched from the EL");

0 commit comments

Comments
 (0)