Skip to content

Commit 3cece13

Browse files
authored
Merge pull request #6 from weaveVM/v2
V2
2 parents 7fec740 + f92343e commit 3cece13

File tree

8 files changed

+1133
-713
lines changed

8 files changed

+1133
-713
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
[package]
22
name = "wvm-blobscan"
3-
version = "1.0.0"
3+
version = "0.2.0"
44
edition = "2021"
55

66
[dependencies]
7-
alloy-chains = "0.1"
7+
alloy-chains = "0.1.0"
88
alloy-primitives = { version = "0.8", default-features = false, features = [
99
"std",
1010
"serde",
1111
] }
12-
alloy-rpc-types-eth = "0.4"
13-
alloy-eips = "0.4"
14-
alloy-serde = "0.4"
15-
16-
foundry-blob-explorers = {git = "https://github.com/charmful0x/block-explorers.git"}
12+
alloy-rpc-types-eth = "0.13.0"
13+
alloy-eips = "0.13.0"
14+
alloy-serde = "0.13.0"
1715
tokio = { version = "1.41.1", features = ["full"]}
1816
ethers = {version = "2.0.14", features = ["ws"]}
1917
eyre = "0.6.12"
@@ -22,8 +20,8 @@ serde = "1.0.215"
2220
serde_json = "1.0.133"
2321
planetscale-driver = "0.5.1"
2422
dotenv = "0.15.0"
25-
anyhow = "1.0.93"
2623
shuttle-runtime = "0.50.0"
2724
shuttle-axum = "0.50.0"
2825
axum = "0.7.9"
29-
reqwest = "0.12.12"
26+
reqwest = {version = "0.12.12", features=["json"]}
27+
anyhow = "1.0.98"

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
<p align="center">
2-
<a href="https://wvm.dev">
3-
<img src="https://github.com/raw/weaveVM/.github/main/profile/bg.png">
4-
</a>
5-
</p>
6-
71
## About
8-
`wvm-blobscan` is a data bridge built to archive Ethereum's blob data on [WeaveVM](https://wvm.dev). It grabs blocks containing eip-4844 transactions from [Blobscan](https://blobscan.com) and archive them permanently on WeaveVM..
2+
`wvm-blobscan` is a data bridge built to archive Ethereum's blob data on [Load Network](https://load.network). It grabs blocks containing eip-4844 transactions from [Blobscan](https://blobscan.com) and archive them permanently on Load Network.
93

104
### Prerequisites & Dependencies
115

126
While the core functionality of this ETL codebase can run without web2 component dependencies, this node implementation uses [planetscale](https://planetscale.com) for cloud indexing and [shuttle.dev](https://shuttle.dev) for backend hosting. Check [.env.example](./env.example) to set up your environment variables.
137

148
```js
15-
blobscan_pk="" // WeaveVM Blobscan archiver PK
9+
blobscan_pk="" // Load Blobscan archiver PK
1610

1711
DATABASE_HOST="" // planetscale
1812
DATABASE_USERNAME="" // planetscale
@@ -47,7 +41,7 @@ graph TD
4741
### Retrieve blob data and the associated archive txid by VersionedHash
4842

4943
```bash
50-
curl -X GET https://blobscan.wvm.network/v1/blob/$BLOB_VERSIONED_HASH
44+
curl -X GET https://blobscan.load.rs/v1/blob/$BLOB_VERSIONED_HASH
5145
```
5246

5347
Returns the res in the format as in below:
@@ -64,7 +58,7 @@ pub struct PsGetBlockByVersionedHash {
6458
### Retrieve Archiver stats
6559

6660
```bash
67-
curl -X GET https://blobscan.wvm.network/v1/stats
61+
curl -X GET https://blobscan.load.rs/v1/stats
6862
```
6963

7064
## License

src/main.rs

Lines changed: 9 additions & 7 deletions
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}, // backfill_blobscan_blobs
6+
blobscan::{get_blobs_of_block, insert_block},
77
constants::FIRST_ETH_L1_EIP4844_BLOCK,
88
eth::Ethereum,
99
planetscale::get_latest_block_id,
@@ -39,11 +39,13 @@ async fn main(
3939
println!("latest archived block id: {}", latest_archived_block);
4040
let mut block_number = reader_block_number.read().await;
4141
if *block_number > FIRST_ETH_L1_EIP4844_BLOCK && latest_archived_block < *block_number {
42-
let block = get_block_by_id(latest_archived_block + 1).await;
43-
match block {
44-
Ok(block) => {
45-
println!("block response: {:?}", block);
46-
let res = insert_block(block).await;
42+
let target_block_id = latest_archived_block + 1;
43+
let blobs = get_blobs_of_block(target_block_id).await;
44+
println!("GOT BLOBS OF BLOCK #{:?}", target_block_id);
45+
match blobs {
46+
Ok(blobs) => {
47+
println!("INSERTING: {:?} BLOBS", blobs.len());
48+
let res = insert_block(target_block_id, blobs).await;
4749
match res {
4850
Ok(res) => latest_archived_block += 1,
4951
_ => eprintln!("error updating planetscale"),
@@ -61,7 +63,7 @@ async fn main(
6163
let eth_block_updater = tokio::spawn(async move {
6264
loop {
6365
let mut block_number = writer_block_number.write().await;
64-
*block_number += Ethereum::get_latest_eth_block().await.unwrap();
66+
*block_number = Ethereum::get_latest_eth_block().await.unwrap();
6567
println!("Updated Ethereum Block Number: {}", *block_number);
6668
tokio::time::sleep(tokio::time::Duration::from_secs(12)).await;
6769
}

src/utils/blobscan.rs

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,78 @@
11
use {
2-
crate::utils::env_var::get_env_var,
32
crate::utils::{
3+
env_var::get_env_var,
44
planetscale::{ps_archive_block, ps_get_all_versioned_hashes_paginated},
55
types::BlobInfo,
66
wvm::send_wvm_calldata,
77
},
88
eyre::{eyre, Error, Result},
9-
foundry_blob_explorers::{BlockResponse, Client},
10-
reqwest, serde_json,
9+
reqwest,
10+
serde_json::{self, Value},
1111
std::io::{Read, Write},
1212
};
1313

14-
pub async fn get_block_by_id(block_id: u32) -> Result<BlockResponse, Error> {
15-
let block_id = block_id.to_string();
16-
let client = Client::mainnet();
17-
18-
let block = client.block(block_id.parse().unwrap()).await;
14+
pub async fn get_blobs_versioned_hashes_of_block(
15+
block_id: u32,
16+
) -> Result<Vec<String>, eyre::Error> {
17+
let url = format!(
18+
"https://api.blobscan.com/blocks/{}?type=canonical",
19+
block_id
20+
);
21+
let req: Value = reqwest::Client::new()
22+
.get(url)
23+
.send()
24+
.await
25+
.unwrap()
26+
.json()
27+
.await?;
28+
let versioned_hashes: Vec<String> = req
29+
.pointer("/transactions")
30+
.and_then(|txs| txs.as_array())
31+
.map(|txs| {
32+
txs.iter()
33+
.filter_map(|tx| tx.pointer("/blobs"))
34+
.filter_map(|blobs| blobs.as_array())
35+
.flat_map(|blobs| {
36+
blobs
37+
.iter()
38+
.filter_map(|blob| blob.pointer("/versionedHash"))
39+
.filter_map(|hash| hash.as_str())
40+
.map(String::from)
41+
.collect::<Vec<String>>()
42+
})
43+
.collect()
44+
})
45+
.unwrap_or_default();
46+
Ok(versioned_hashes)
47+
}
1948

20-
match block {
21-
Ok(block) => Ok(block),
22-
Err(e) => {
23-
eprintln!("Error getting block: {:?}", e);
24-
return Err(eyre!("Error getting block: {:?}", e));
25-
}
26-
}
49+
async fn get_blob_data(versioned_hash: &str) -> Result<String, eyre::Error> {
50+
let url = format!("https://api.blobscan.com/blobs/{}/data", versioned_hash);
51+
let res = reqwest::Client::new()
52+
.get(url)
53+
.send()
54+
.await?
55+
.text()
56+
.await
57+
.unwrap_or_default();
58+
Ok(res)
2759
}
2860

29-
pub fn get_blobs_of_block(block: BlockResponse) -> Result<Vec<BlobInfo>> {
61+
pub async fn get_blobs_of_block(block_id: u32) -> Result<Vec<BlobInfo>> {
62+
let versioned_hashes = get_blobs_versioned_hashes_of_block(block_id)
63+
.await
64+
.unwrap_or_default();
3065
let mut res: Vec<BlobInfo> = Vec::new();
31-
let txs = block.transactions;
32-
for _tx in txs {
33-
let blobs = _tx.blobs;
34-
35-
println!("BLOCKS COUNT IN BLOCK #{} is {}", block.number, blobs.len());
36-
37-
for _blob in blobs {
38-
let to_blob_info = BlobInfo::from(
39-
block.number,
40-
_blob.versioned_hash.to_string(),
41-
_blob.data.to_string(),
42-
);
43-
// println!("{:?}", to_blob_info);
44-
res.push(to_blob_info);
45-
}
66+
for hash in versioned_hashes {
67+
let blob_data = get_blob_data(&hash).await.unwrap();
68+
69+
let blob = BlobInfo {
70+
ethereum_block_number: block_id as u64,
71+
versioned_hash: hash,
72+
data: blob_data,
73+
};
74+
75+
res.push(blob);
4676
}
4777

4878
Ok(res)
@@ -54,21 +84,13 @@ pub fn serialize_blobscan_block(block: &BlobInfo) -> Result<Vec<u8>> {
5484
Ok(compressed_data)
5585
}
5686

57-
pub async fn insert_block(block: BlockResponse) -> Result<(), Error> {
58-
let blobs = get_blobs_of_block(block.clone())?;
59-
87+
pub async fn insert_block(block_id: u32, blobs: Vec<BlobInfo>) -> Result<(), Error> {
6088
for blob in blobs {
6189
let wvm_data_input = serialize_blobscan_block(&blob)?;
62-
let raw_block_data = serde_json::to_string(&blob)?;
6390
let wvm_txid = send_wvm_calldata(wvm_data_input).await.unwrap();
64-
let res = ps_archive_block(
65-
&(block.clone().number as u32),
66-
&wvm_txid,
67-
&blob.versioned_hash,
68-
&blob.data,
69-
)
70-
.await
71-
.unwrap();
91+
let _res = ps_archive_block(&block_id, &wvm_txid, &blob.versioned_hash, &blob.data)
92+
.await
93+
.unwrap();
7294
let _send_to_blobscan = send_blob_to_blobscan(&blob.versioned_hash).await.unwrap();
7395
}
7496

src/utils/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub const FIRST_ETH_L1_EIP4844_BLOCK: u32 = 19_426_589;
22
pub const ETH_RPC_URL: &str = "https://eth.llamarpc.com";
3-
pub const WVM_RPC_URL: &str = "https://testnet-rpc.wvm.dev";
3+
pub const WVM_RPC_URL: &str = "https://alphanet.load.network";
44
pub const WVM_CHAIN_ID: u32 = 9496;
55
pub const WVM_ARCHIVER_ADDRESS: &str = "0x2BC885e26A3947646FAbb96C68cE82f5937038a7";

src/utils/planetscale.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub async fn ps_archive_block(
2727
) -> Result<(), Error> {
2828
// format to the table VAR(66) limitation
2929
let wvm_calldata_txid = wvm_calldata_txid.trim_matches('"');
30+
let blob_data = blob_data.trim_matches('"');
3031
let conn = ps_init().await;
3132

3233
let res = query(

src/utils/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ impl BlobInfo {
3939
}
4040
}
4141
}
42+
43+
impl std::fmt::Display for BlobInfo {
44+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45+
write!(
46+
f,
47+
"Block: {}, Hash: {}, Data: {}",
48+
self.ethereum_block_number, self.versioned_hash, self.data
49+
)
50+
}
51+
}

0 commit comments

Comments
 (0)