Skip to content

Commit 7fec740

Browse files
authored
Merge pull request #5 from weaveVM/dev
chore: backfill blobs in blobscan service
2 parents e6e4075 + 70ebc9f commit 7fec740

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use {
33
std::sync::Arc,
44
tokio::sync::RwLock,
55
utils::{
6-
blobscan::{get_block_by_id, insert_block},
6+
blobscan::{get_block_by_id, insert_block}, // backfill_blobscan_blobs
77
constants::FIRST_ETH_L1_EIP4844_BLOCK,
88
eth::Ethereum,
99
planetscale::get_latest_block_id,
@@ -31,6 +31,8 @@ async fn main(
3131
let reader_block_number = block_number.clone();
3232
let writer_block_number = block_number.clone();
3333

34+
// backfill_blobscan_blobs(3).await;
35+
3436
let blobscan_insertion = tokio::spawn(async move {
3537
let mut latest_archived_block = get_latest_block_id().await;
3638
loop {

src/utils/blobscan.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use {
22
crate::utils::env_var::get_env_var,
3-
crate::utils::{planetscale::ps_archive_block, types::BlobInfo, wvm::send_wvm_calldata},
3+
crate::utils::{
4+
planetscale::{ps_archive_block, ps_get_all_versioned_hashes_paginated},
5+
types::BlobInfo,
6+
wvm::send_wvm_calldata,
7+
},
48
eyre::{eyre, Error, Result},
59
foundry_blob_explorers::{BlockResponse, Client},
610
reqwest, serde_json,
@@ -104,3 +108,42 @@ pub async fn send_blob_to_blobscan(blob_hash: &str) -> Result<(), Error> {
104108

105109
Ok(())
106110
}
111+
112+
// pub async fn send_blobs_to_blobscan(blob_hash: Vec<&str>) -> Result<(), Error> {
113+
// let client = reqwest::Client::new();
114+
// let key = get_env_var("blobscan_api_key").unwrap();
115+
// let response = client
116+
// .post("https://api.blobscan.com/blobs/weavevm-references")
117+
// .header("Authorization", key)
118+
// .json(&serde_json::json!({
119+
// "blobHashes": blob_hash
120+
// }))
121+
// .send()
122+
// .await?;
123+
124+
// println!("Status: {}", response.status());
125+
// println!("Headers: {:?}", response.headers());
126+
127+
// Ok(())
128+
// }
129+
130+
// pub async fn backfill_blobscan_blobs(page: u32) {
131+
// for page in 0..page {
132+
// let mut temp_hashes: Vec<&str> = vec![];
133+
// let mut i = 0;
134+
// let batch = ps_get_all_versioned_hashes_paginated(page).await;
135+
136+
// for el in &batch {
137+
// let hash = &el.versioned_hash;
138+
// temp_hashes.push(&hash);
139+
// }
140+
// println!("Fetched {} blobs", temp_hashes.len());
141+
// println!("sending blobs on 10ks to blobscan");
142+
143+
// while i < 100_000 {
144+
// println!("{} {}", i, i + 10_000);
145+
// let _ = send_blobs_to_blobscan(temp_hashes[i..i + 10_000].to_vec()).await.unwrap();
146+
// i += 10_000;
147+
// }
148+
// }
149+
// }

src/utils/planetscale.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::utils::{
33
constants::FIRST_ETH_L1_EIP4844_BLOCK,
44
env_var::get_env_var,
5-
types::{PsGetBlockByVersionedHash, PsGetLatestArchivedBlock},
5+
types::{PsGetBlockByVersionedHash, PsGetLatestArchivedBlock, VersionedHashOnly},
66
},
77
anyhow::Error,
88
planetscale_driver::{query, PSConnection},
@@ -87,3 +87,20 @@ pub async fn ps_get_blob_data_by_versioned_hash(versioned_hash: &str) -> Value {
8787
let res = serde_json::json!(ps_result);
8888
res
8989
}
90+
91+
pub async fn ps_get_all_versioned_hashes_paginated(page: u32) -> Vec<VersionedHashOnly> {
92+
let conn = ps_init().await;
93+
let offset = page * 100000;
94+
95+
let query_str = format!(
96+
"SELECT VersionedHash FROM Blobscan LIMIT 100000 OFFSET {};",
97+
offset
98+
);
99+
100+
let ps_results: Vec<VersionedHashOnly> = match query(&query_str).fetch_all(&conn).await {
101+
Ok(results) => results,
102+
Err(e) => panic!("Database query failed: {}", e),
103+
};
104+
105+
ps_results
106+
}

src/utils/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ use {
22
planetscale_driver::Database,
33
serde::{Deserialize, Serialize},
44
};
5+
6+
#[derive(Debug, Serialize, Deserialize, Database)]
7+
pub struct VersionedHashOnly {
8+
pub versioned_hash: String,
9+
}
10+
511
#[derive(Debug, Serialize, Deserialize, Database)]
612
pub struct PsGetBlockByVersionedHash {
713
pub ethereum_block_number: u64,

0 commit comments

Comments
 (0)