From e766a0d82599aea8115ac52a26718f52697e2cbe Mon Sep 17 00:00:00 2001 From: Vaclav Barta Date: Mon, 22 Apr 2024 11:10:44 +0200 Subject: [PATCH] removed #77 (no longer works) --- Cargo.lock | 16 ------ Cargo.toml | 2 - state-reconstruct-fetcher/Cargo.toml | 1 - .../blobscan-client/Cargo.toml | 14 ----- .../blobscan-client/src/blob_support.rs | 19 ------- .../blobscan-client/src/lib.rs | 4 -- .../blobscan-client/src/scraping_support.rs | 52 ------------------- state-reconstruct-fetcher/src/api_support.rs | 30 ----------- .../src/blob_http_client.rs | 38 +++++++++++--- state-reconstruct-fetcher/src/l1_fetcher.rs | 16 ++---- state-reconstruct-fetcher/src/lib.rs | 1 - state-reconstruct-fetcher/src/types/mod.rs | 3 +- 12 files changed, 34 insertions(+), 162 deletions(-) delete mode 100644 state-reconstruct-fetcher/blobscan-client/Cargo.toml delete mode 100644 state-reconstruct-fetcher/blobscan-client/src/blob_support.rs delete mode 100644 state-reconstruct-fetcher/blobscan-client/src/lib.rs delete mode 100644 state-reconstruct-fetcher/blobscan-client/src/scraping_support.rs delete mode 100644 state-reconstruct-fetcher/src/api_support.rs diff --git a/Cargo.lock b/Cargo.lock index 2128815..fb90fa4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -444,20 +444,6 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "blobscan-client" -version = "0.1.0" -dependencies = [ - "eyre", - "hex", - "reqwest", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "block-buffer" version = "0.7.3" @@ -4443,7 +4429,6 @@ dependencies = [ "async-trait", "bincode", "blake2 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", - "blobscan-client", "chrono", "clap", "ethers", @@ -4471,7 +4456,6 @@ version = "0.1.0" dependencies = [ "bincode", "blake2 0.10.6 (registry+https://github.com/rust-lang/crates.io-index)", - "blobscan-client", "chrono", "ethers", "eyre", diff --git a/Cargo.toml b/Cargo.toml index dca3786..c3297d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [workspace] members = [ "state-reconstruct-fetcher", - "state-reconstruct-fetcher/blobscan-client", "state-reconstruct-storage", ] @@ -15,7 +14,6 @@ members = [ async-trait = "0.1.74" bincode = "1" blake2 = "0.10.6" -blobscan-client = { path = "./state-reconstruct-fetcher/blobscan-client" } chrono = "0.4.31" clap = { version = "4.4.7", features = ["derive", "env"] } ethers = "1.0.2" diff --git a/state-reconstruct-fetcher/Cargo.toml b/state-reconstruct-fetcher/Cargo.toml index 488e72d..6c7f48e 100644 --- a/state-reconstruct-fetcher/Cargo.toml +++ b/state-reconstruct-fetcher/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" [dependencies] bincode = "1.3.3" blake2 = "0.10.6" -blobscan-client = { path = "./blobscan-client" } ethers = "1.0.2" eyre = "0.6.8" indexmap = { version = "2.0.2", features = ["serde"] } diff --git a/state-reconstruct-fetcher/blobscan-client/Cargo.toml b/state-reconstruct-fetcher/blobscan-client/Cargo.toml deleted file mode 100644 index 97f1832..0000000 --- a/state-reconstruct-fetcher/blobscan-client/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "blobscan-client" -version = "0.1.0" -edition = "2021" - -[dependencies] -eyre = "0.6.8" -hex = "0.4.3" -reqwest = "0.11.24" -serde = { version = "1.0.189", features = ["derive"] } -serde_json = { version = "1.0.107", features = ["std"] } -thiserror = "1.0.50" -tokio = { version = "1.33.0", features = ["signal"] } -tracing = "0.1.40" diff --git a/state-reconstruct-fetcher/blobscan-client/src/blob_support.rs b/state-reconstruct-fetcher/blobscan-client/src/blob_support.rs deleted file mode 100644 index 13c4a29..0000000 --- a/state-reconstruct-fetcher/blobscan-client/src/blob_support.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::fmt; - -use thiserror::Error; - -#[allow(clippy::enum_variant_names)] -#[derive(Error, Debug)] -pub struct BlobResponseFormatError(pub String, pub String); - -impl fmt::Display for BlobResponseFormatError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}: {}", self.0, self.1) - } -} - -pub trait BlobSupport { - fn format_url(&self, kzg_commitment: &[u8]) -> String; - - fn get_blob_data(&self, json_str: &str) -> Result; -} diff --git a/state-reconstruct-fetcher/blobscan-client/src/lib.rs b/state-reconstruct-fetcher/blobscan-client/src/lib.rs deleted file mode 100644 index 40887ef..0000000 --- a/state-reconstruct-fetcher/blobscan-client/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod blob_support; -pub use crate::blob_support::{BlobResponseFormatError, BlobSupport}; -mod scraping_support; -pub use crate::scraping_support::ScrapingSupport; diff --git a/state-reconstruct-fetcher/blobscan-client/src/scraping_support.rs b/state-reconstruct-fetcher/blobscan-client/src/scraping_support.rs deleted file mode 100644 index 7f8818a..0000000 --- a/state-reconstruct-fetcher/blobscan-client/src/scraping_support.rs +++ /dev/null @@ -1,52 +0,0 @@ -use serde::Deserialize; -use serde_json::json; - -use crate::blob_support::{BlobResponseFormatError, BlobSupport}; - -#[derive(Deserialize)] -struct JsonResponse { - result: JsonResponseResult, -} - -#[derive(Deserialize)] -struct JsonResponseResult { - data: JsonResponseData, -} - -#[derive(Deserialize)] -struct JsonResponseData { - json: JsonResponseJson, -} - -#[derive(Deserialize)] -struct JsonResponseJson { - data: String, -} - -#[derive(Default)] -pub struct ScrapingSupport; - -impl BlobSupport for ScrapingSupport { - fn format_url(&self, kzg_commitment: &[u8]) -> String { - let id = format!("0x{}", hex::encode(kzg_commitment)); - let json_source = json!({ - "json": { - "id": id - } - }); - let json_string = json_source.to_string(); - let url = reqwest::Url::parse_with_params( - "https://blobscan.com/api/trpc/blob.getByBlobIdFull", - &[("input", &json_string)], - ) - .unwrap(); - url.to_string() - } - - fn get_blob_data(&self, json_str: &str) -> Result { - match serde_json::from_str::(json_str) { - Ok(rsp) => Ok(rsp.result.data.json.data), - Err(e) => Err(BlobResponseFormatError(json_str.to_string(), e.to_string())), - } - } -} diff --git a/state-reconstruct-fetcher/src/api_support.rs b/state-reconstruct-fetcher/src/api_support.rs deleted file mode 100644 index ca5db94..0000000 --- a/state-reconstruct-fetcher/src/api_support.rs +++ /dev/null @@ -1,30 +0,0 @@ -use blobscan_client::{BlobResponseFormatError, BlobSupport}; -use serde::Deserialize; - -#[derive(Deserialize)] -struct JsonResponse { - data: String, -} - -pub struct ApiSupport { - url_base: String, -} - -impl ApiSupport { - pub fn new(blob_url: String) -> Self { - Self { url_base: blob_url } - } -} - -impl BlobSupport for ApiSupport { - fn format_url(&self, kzg_commitment: &[u8]) -> String { - format!("{}0x{}", self.url_base, hex::encode(kzg_commitment)) - } - - fn get_blob_data(&self, json_str: &str) -> Result { - match serde_json::from_str::(json_str) { - Ok(data) => Ok(data.data), - Err(e) => Err(BlobResponseFormatError(json_str.to_string(), e.to_string())), - } - } -} diff --git a/state-reconstruct-fetcher/src/blob_http_client.rs b/state-reconstruct-fetcher/src/blob_http_client.rs index 391dad7..93ef262 100644 --- a/state-reconstruct-fetcher/src/blob_http_client.rs +++ b/state-reconstruct-fetcher/src/blob_http_client.rs @@ -1,4 +1,4 @@ -use blobscan_client::{BlobResponseFormatError, BlobSupport}; +use serde::Deserialize; use tokio::time::{sleep, Duration}; use crate::types::ParseError; @@ -8,13 +8,18 @@ const MAX_RETRIES: u8 = 5; /// The interval in seconds to wait before retrying to fetch a blob. const FAILED_FETCH_RETRY_INTERVAL_S: u64 = 10; +#[derive(Deserialize)] +struct JsonResponse { + data: String, +} + pub struct BlobHttpClient { client: reqwest::Client, - support: Box, + url_base: String, } impl BlobHttpClient { - pub fn new(support: Box) -> eyre::Result { + pub fn new(blob_url: String) -> eyre::Result { let mut headers = reqwest::header::HeaderMap::new(); headers.insert( "Accept", @@ -23,15 +28,18 @@ impl BlobHttpClient { let client = reqwest::Client::builder() .default_headers(headers) .build()?; - Ok(Self { client, support }) + Ok(Self { + client, + url_base: blob_url, + }) } pub async fn get_blob(&self, kzg_commitment: &[u8]) -> Result, ParseError> { - let url = self.support.format_url(kzg_commitment); + let url = self.format_url(kzg_commitment); for attempt in 1..=MAX_RETRIES { match self.client.get(&url).send().await { Ok(response) => match response.text().await { - Ok(text) => match self.support.get_blob_data(&text) { + Ok(text) => match get_blob_data(&text) { Ok(data) => { let plain = if let Some(p) = data.strip_prefix("0x") { p @@ -39,12 +47,12 @@ impl BlobHttpClient { &data }; return hex::decode(plain).map_err(|e| { - BlobResponseFormatError(plain.to_string(), e.to_string()).into() + ParseError::BlobFormatError(plain.to_string(), e.to_string()) }); } Err(e) => { tracing::error!("failed parsing response of {url}"); - return Err(e.into()); + return Err(e); } }, Err(e) => { @@ -60,4 +68,18 @@ impl BlobHttpClient { } Err(ParseError::BlobStorageError(url)) } + + fn format_url(&self, kzg_commitment: &[u8]) -> String { + format!("{}0x{}", self.url_base, hex::encode(kzg_commitment)) + } +} + +fn get_blob_data(json_str: &str) -> Result { + match serde_json::from_str::(json_str) { + Ok(data) => Ok(data.data), + Err(e) => Err(ParseError::BlobFormatError( + json_str.to_string(), + e.to_string(), + )), + } } diff --git a/state-reconstruct-fetcher/src/l1_fetcher.rs b/state-reconstruct-fetcher/src/l1_fetcher.rs index 594adaf..809767c 100644 --- a/state-reconstruct-fetcher/src/l1_fetcher.rs +++ b/state-reconstruct-fetcher/src/l1_fetcher.rs @@ -1,6 +1,5 @@ use std::{cmp, fs::File, future::Future, sync::Arc}; -use blobscan_client::{BlobSupport, ScrapingSupport}; use ethers::{ abi::{Contract, Function}, prelude::*, @@ -16,7 +15,6 @@ use tokio::{ use tokio_util::sync::CancellationToken; use crate::{ - api_support::ApiSupport, blob_http_client::BlobHttpClient, constants::ethereum::{BLOB_BLOCK, BLOCK_STEP, BOOJUM_BLOCK, GENESIS_BLOCK, ZK_SYNC_ADDR}, metrics::L1Metrics, @@ -468,7 +466,7 @@ impl L1Fetcher { ) -> Result>> { let metrics = self.metrics.clone(); let contracts = self.contracts.clone(); - let client = BlobHttpClient::new(make_support(self.config.blobs_url.clone()))?; + let client = BlobHttpClient::new(self.config.blobs_url.clone())?; Ok(tokio::spawn({ async move { let mut boojum_mode = false; @@ -507,8 +505,8 @@ impl L1Fetcher { } sleep(Duration::from_secs(LONG_POLLING_INTERVAL_S)).await; } - ParseError::BlobFormatError(inner) => { - tracing::error!("Cannot parse {}: {}", inner.0, inner.1); + ParseError::BlobFormatError(data, inner) => { + tracing::error!("Cannot parse {}: {}", data, inner); cancellation_token.cancel(); return last_block_number_processed; } @@ -564,14 +562,6 @@ impl L1Fetcher { } } -fn make_support(url: String) -> Box { - if url.starts_with("https://blobscan.com") { - Box::::default() - } else { - Box::new(ApiSupport::new(url)) - } -} - pub async fn parse_calldata( l1_block_number: u64, commit_blocks_fn: &Function, diff --git a/state-reconstruct-fetcher/src/lib.rs b/state-reconstruct-fetcher/src/lib.rs index f237ef5..881cdae 100644 --- a/state-reconstruct-fetcher/src/lib.rs +++ b/state-reconstruct-fetcher/src/lib.rs @@ -1,7 +1,6 @@ #![feature(array_chunks)] #![feature(iter_next_chunk)] -pub mod api_support; pub mod blob_http_client; pub mod constants; pub mod l1_fetcher; diff --git a/state-reconstruct-fetcher/src/types/mod.rs b/state-reconstruct-fetcher/src/types/mod.rs index 4a2308c..409a874 100644 --- a/state-reconstruct-fetcher/src/types/mod.rs +++ b/state-reconstruct-fetcher/src/types/mod.rs @@ -1,4 +1,3 @@ -use blobscan_client::BlobResponseFormatError; use ethers::{abi, types::U256}; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; @@ -41,7 +40,7 @@ pub enum ParseError { BlobStorageError(String), #[error("blob format error: {0}")] - BlobFormatError(#[from] BlobResponseFormatError), + BlobFormatError(String, String), } #[derive(Debug, Serialize, Deserialize)]