From f2aa6f29268e21520bd7c9d9186f82de0b0058b0 Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Mon, 9 Dec 2024 11:17:46 -0300 Subject: [PATCH] initial commit --- get_all_blobs/src/client.rs | 42 ++++++++++++++++++++++++++++++++----- get_all_blobs/src/main.rs | 18 ++++++++++------ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/get_all_blobs/src/client.rs b/get_all_blobs/src/client.rs index 0996b150a472..f7da1a1ca70d 100644 --- a/get_all_blobs/src/client.rs +++ b/get_all_blobs/src/client.rs @@ -4,7 +4,7 @@ use tonic::transport::{Channel, ClientTlsConfig, Endpoint}; use crate::{ blob_info::BlobInfo, - generated::{disperser, disperser::disperser_client::DisperserClient}, + generated::disperser::{self, disperser_client::DisperserClient}, }; #[derive(Debug, Clone)] @@ -22,10 +22,7 @@ impl EigenClientRetriever { Ok(EigenClientRetriever { client }) } - pub async fn get_blob_data(&self, blob_id: &str) -> anyhow::Result>> { - let commit = hex::decode(blob_id)?; - - let blob_info: BlobInfo = rlp::decode(&commit)?; + pub async fn get_blob_data(&self, blob_info: BlobInfo) -> anyhow::Result>> { let blob_index = blob_info.blob_verification_proof.blob_index; let batch_header_hash = blob_info .blob_verification_proof @@ -49,4 +46,39 @@ impl EigenClientRetriever { let data = kzgpad_rs::remove_empty_byte_from_padded_bytes(&get_response.data); Ok(Some(data)) } + + pub async fn get_blob_status(&self, blob_id: &str) -> anyhow::Result> { + let polling_request = disperser::BlobStatusRequest { + request_id: hex::decode(blob_id)?, + }; + + let resp = self + .client + .clone() + .get_blob_status(polling_request.clone()) + .await? + .into_inner(); + + match disperser::BlobStatus::try_from(resp.status)? { + disperser::BlobStatus::Processing | disperser::BlobStatus::Dispersing => Ok(None), + disperser::BlobStatus::Failed => Err(anyhow::anyhow!("Blob dispatch failed")), + disperser::BlobStatus::InsufficientSignatures => { + Err(anyhow::anyhow!("Insufficient signatures")) + } + disperser::BlobStatus::Confirmed => { + let blob_info = resp + .info + .ok_or_else(|| anyhow::anyhow!("No blob header in response"))?; + Ok(Some(blob_info.try_into().unwrap())) + } + disperser::BlobStatus::Finalized => { + let blob_info = resp + .info + .ok_or_else(|| anyhow::anyhow!("No blob header in response"))?; + Ok(Some(blob_info.try_into().unwrap())) + } + + _ => Err(anyhow::anyhow!("Received unknown blob status")), + } + } } diff --git a/get_all_blobs/src/main.rs b/get_all_blobs/src/main.rs index 215108d554ed..33c2c67648fc 100644 --- a/get_all_blobs/src/main.rs +++ b/get_all_blobs/src/main.rs @@ -16,7 +16,7 @@ mod generated; #[derive(Debug, Serialize, Deserialize)] struct BlobData { - pub commitment: String, + pub blob_id: String, pub blob: String, } @@ -27,10 +27,16 @@ const COMMIT_BATCHES_SELECTOR: &str = "6edd4f12"; async fn get_blob(commitment: &str) -> anyhow::Result> { let client = EigenClientRetriever::new(EIGENDA_API_URL).await?; + let blob_id = commitment; + let blob_info = client + .get_blob_status(blob_id) + .await? + .ok_or_else(|| anyhow::anyhow!("Blob not found"))?; let data = client - .get_blob_data(commitment) + .get_blob_data(blob_info) .await? .ok_or_else(|| anyhow::anyhow!("Blob not found"))?; + Ok(data) } @@ -128,11 +134,11 @@ async fn get_blob_from_pubdata_commitment( )); } let pubdata_commitments_bytes = pubdata_commitments_bytes.unwrap(); - let commitment = hex::decode(&pubdata_commitments_bytes[1..])?; - let commitment = hex::encode(&commitment); - let blob = get_blob(&commitment).await?; + let blob_id = hex::decode(&pubdata_commitments_bytes[1..])?; + let blob_id = hex::encode(&blob_id); + let blob = get_blob(&blob_id).await?; Ok(BlobData { - commitment, + blob_id, blob: hex::encode(blob), }) }