Skip to content

Commit 8a833fa

Browse files
committed
docs: document functions and structs
1 parent ac33e6c commit 8a833fa

File tree

9 files changed

+62
-33
lines changed

9 files changed

+62
-33
lines changed

src/core/blobscan.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Module to handle blobscan API operations.
2-
//!
2+
//!
33
//! Functionalities:
44
//! - Fetch blobs from a given Ethereum block number
55
//! - Fetch blobs' versioned hashes for a given Ethereum block number
66
//! - Fetch blob data for a given blob versioned hash
77
//! - Serialize BlobInfo as Arweave's ANS-104 DataItem
8-
//! - Send the stored blob to Blobscan's API
8+
//! - Send the stored blob to Blobscan's API - /weavevm-references endpoint
99
1010
use crate::core::{env_var::get_env_var, types::BlobInfo};
1111
use anyhow::Error;
@@ -16,6 +16,7 @@ use bundles_rs::{
1616
use reqwest;
1717
use serde_json::{self, Value};
1818

19+
/// Get a vector of the blobs versioned hashes in a given Ethereum block number.
1920
pub async fn get_blobs_versioned_hashes_of_block(block_id: u64) -> Result<Vec<String>, Error> {
2021
let url = format!("https://api.blobscan.com/blocks/{}?type=canonical", block_id);
2122
let req: Value = reqwest::Client::new().get(url).send().await.unwrap().json().await?;
@@ -40,12 +41,14 @@ pub async fn get_blobs_versioned_hashes_of_block(block_id: u64) -> Result<Vec<St
4041
Ok(versioned_hashes)
4142
}
4243

44+
/// Get the blob's data field (hex) for a given blob's versioned hash.
4345
async fn get_blob_data(versioned_hash: &str) -> Result<String, Error> {
4446
let url = format!("https://api.blobscan.com/blobs/{}/data", versioned_hash);
4547
let res = reqwest::Client::new().get(url).send().await?.text().await.unwrap_or_default();
4648
Ok(res)
4749
}
4850

51+
/// Get a vector of blobs as BlobInfo for a given Ethereum block number.
4952
pub async fn get_blobs_of_block(block_id: u64) -> Result<Vec<BlobInfo>, Error> {
5053
let versioned_hashes = get_blobs_versioned_hashes_of_block(block_id).await.unwrap_or_default();
5154
let mut res: Vec<BlobInfo> = Vec::new();
@@ -64,6 +67,8 @@ pub async fn get_blobs_of_block(block_id: u64) -> Result<Vec<BlobInfo>, Error> {
6467
Ok(res)
6568
}
6669

70+
/// Serialize the BlobInfo as ANS-104 DataItem, sign it using the agent's Arweave JWK
71+
/// and return DataItem raw bytes and its deterministic ID.
6772
pub fn serialize_blobscan_block(block: &BlobInfo) -> Result<(Vec<u8>, String), Error> {
6873
let data = serde_json::to_vec(&block)?;
6974
let tags =
@@ -74,7 +79,8 @@ pub fn serialize_blobscan_block(block: &BlobInfo) -> Result<(Vec<u8>, String), E
7479
Ok((dataitem.to_bytes().unwrap(), dataitem.arweave_id()))
7580
}
7681

77-
pub async fn send_blob_to_blobscan(blob_hash: &str) -> Result<(), Error> {
82+
/// Index the blob's versioned_hash -> data_item_id on Blobscan
83+
pub(crate) async fn send_blob_to_blobscan(blob_hash: &str) -> Result<(), Error> {
7884
let client = reqwest::Client::new();
7985
let key = get_env_var("blobscan_api_key").unwrap();
8086
let response = client

src/core/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
pub const FIRST_ETH_L1_EIP4844_BLOCK: u64 = 19426596; // test: 19426596 -- correct: 19_426_589
33
pub const ETH_RPC_URL: &str = "https://eth.llamarpc.com";
44
pub const BLOBSCAN_AGENT_ADDRESS: &str = "nb0VFuKAdWNvsw-H8bktG89uWaZuC-DFg4b2EcUlFI0";
5+
pub const HYPERBEAM_S3_HYBRID_GATEWAY_ENDPOINT: &str = "https://s3-node-0.load.network";

src/core/eth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Module to interact with an Ethereum JSON-RPC client
2-
//!
2+
//!
33
//! Functionalities:
44
//! - Get the latest Ethereum block number
5-
//!
5+
//!
66
//! Note: this modules should migrate to alloy-rs instead of using ethers
77
use crate::core::constants::ETH_RPC_URL;
88
use anyhow::Error;

src/core/indexer.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Agent's indexer module - uses planetscale to index
22
//! metadata about the Ethereum blobs stored as ANS-104 offchain
33
//! DataItems on Load's HyperBEAM S3 node.
4-
//!
4+
//!
55
//! Functionalities:
66
//! - Map a blob versioned hash to the corresponding offchain ANS-104 DataItem ID
77
//! - Get the DataItem ID for a given blob versioned hash
@@ -14,19 +14,25 @@ use planetscale_driver::{query, Database, PSConnection};
1414
use serde::{Deserialize, Serialize};
1515
use serde_json::Value;
1616

17+
/// Structure used by the indexer to parse the metadata's pair.
1718
#[derive(Debug, Default, Database, Serialize, Deserialize)]
1819
pub(crate) struct GetVersionedHash {
20+
/// Blob's versioned hash
1921
pub versioned_hash: String,
22+
/// ~s3@1.0 ANS-104 DataItem ID
2023
pub arweave_txid: String,
2124
}
22-
25+
/// Structure to parse the indexer's stats response.
2326
#[derive(Debug, Default, Database, Serialize, Deserialize)]
2427
pub(crate) struct GetIndexerStats {
28+
/// Latest processed blob's versioned hash
2529
pub versioned_hash: String,
30+
/// Latest processed blob's DataItem ID
2631
pub arweave_txid: String,
32+
/// Latest processed Etehreum block number containing blobs
2733
pub ethereum_block_number: u64,
2834
}
29-
35+
/// Initialize Planetscale connection
3036
async fn ps_init() -> PSConnection {
3137
let host = get_env_var("DATABASE_HOST").unwrap();
3238
let username = get_env_var("DATABASE_USERNAME").unwrap();
@@ -36,7 +42,8 @@ async fn ps_init() -> PSConnection {
3642

3743
conn
3844
}
39-
45+
/// Insert the pair of metadata consisting of blob's versioned hash, its
46+
/// corresponding offchain DataItem ID, and the carrier ethereum block number.
4047
pub async fn insert_kv(
4148
versioned_hash: &str,
4249
arweave_txid: &str,
@@ -53,7 +60,7 @@ pub async fn insert_kv(
5360

5461
Ok(res)
5562
}
56-
63+
/// Get the metadata pair (versioned hash, DataItem ID) for a given blob's versioned hash.
5764
pub async fn get_versioned_hash_value(versioned_hash: &str) -> Result<Value, Error> {
5865
let client = ps_init().await;
5966

@@ -66,7 +73,7 @@ pub async fn get_versioned_hash_value(versioned_hash: &str) -> Result<Value, Err
6673

6774
Ok(serde_json::to_value(res)?)
6875
}
69-
76+
/// Get the latest processed Ethereum block number that contains an EIP-4844 tx.
7077
pub async fn get_latest_block_id() -> u64 {
7178
let client = ps_init().await;
7279
let res: u64 =
@@ -76,7 +83,8 @@ pub async fn get_latest_block_id() -> u64 {
7683
.unwrap_or(FIRST_ETH_L1_EIP4844_BLOCK);
7784
return res;
7885
}
79-
86+
/// Get the indexer's stats - it returns the latest fields that contains
87+
/// a blob (a block with EIP-4844 tx).
8088
pub async fn get_indexer_stats() -> Result<Value, Error> {
8189
let client = ps_init().await;
8290
let res: GetIndexerStats = query("SELECT versioned_hash, arweave_txid, ethereum_block_number FROM blobscan_arweave_mapping WHERE ethereum_block_number = (SELECT MAX(ethereum_block_number) FROM blobscan_arweave_mapping) LIMIT 1;").fetch_one(&client).await.unwrap();

src/core/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Core modules for the Blobscan Agent.
2-
//!
2+
//!
33
//! This module contains all the core functionality organized into specialized
44
//! submodules for handling different aspects of the blob retrieval and storage
55
//! pipeline.
6-
//!
6+
//!
77
//! ## Module Organization:
88
//! - `blobscan` - Blobscan API integration and blob fetching
99
//! - `constants` - Application-wide constants and configuration

src/core/s3.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Module to interact with Load's S3 HyperBEAM device (~s3@1.0).
22
//! The module store the serialized Ethereum blobs as ANS-104 DataItems
3-
//! in a a location in the HyperBEAM device where it can be retrieved back from
3+
//! in a a location in the HyperBEAM device where it can be retrieved back from
44
//! the Load HyperBEAM Hybrid Gateway as if it is an onchain Arweave DataItem
55
//! To learn more about Hybrid Gateway and retrieval logic, check the load_hb
6-
//! documentation: https://github.com/loadnetwork/load_hb/tree/s3-edge/native/s3_nif#hybrid-gateway
7-
//!
8-
//! Functionalities:
6+
//! documentation: https://github.com/loadnetwork/load_hb/tree/s3-edge/native/s3_nif#hybrid-gateway
7+
//!
8+
//! Functionalities:
99
//! - Initialize ~s3@1.0 device connection
1010
//! - Store Ethereum blob as BlobInfo struct, serialized as ANS-104 DataItem
1111
//! - Retrieve a blob and its data (deserialized) back from the ~s3@1.0 for a given versione hash
@@ -16,7 +16,7 @@ use anyhow::{anyhow, Error};
1616
use aws_config::{BehaviorVersion, Region};
1717
use aws_sdk_s3::Client;
1818
use serde_json::Value;
19-
19+
/// Initialize the ~s3@1.0 device connection using the aws s3 sdk.
2020
async fn s3_client() -> Result<Client, Error> {
2121
let config = aws_config::defaults(BehaviorVersion::latest())
2222
.endpoint_url(get_env_var("AWS_ENDPOINT_URL").unwrap())
@@ -32,7 +32,12 @@ async fn s3_client() -> Result<Client, Error> {
3232
.await;
3333
Ok(Client::new(&config))
3434
}
35-
35+
/// Store a blob's BlobInfo as a signed valid ANS-104 DataItem. The DataItem is stored
36+
/// as an object in the HyperBEAM S3 device and is retrievable from the Load hyperbeam
37+
/// Hybrid Gateway as it was an onchain DataItem, providing a full backward compatibility
38+
/// with the Arweave's ecosystem and integration techstack - and most importantly, it offers
39+
/// a deterministic route for the offchain S3 DataItems to be posted onchain to Arweave while
40+
/// maintaining blob's DataItem integrity and provenance.
3641
pub async fn store_blob(versioned_hash: &str, blob_data: &str, block_id: u64) -> Result<(), Error> {
3742
let client = s3_client().await;
3843
let s3_bucket_name = get_env_var("S3_BUCKET_NAME").unwrap();
@@ -56,7 +61,8 @@ pub async fn store_blob(versioned_hash: &str, blob_data: &str, block_id: u64) ->
5661

5762
Ok(())
5863
}
59-
64+
/// Get a JSON serialized BlobInfo object for a given blob;s versioned hash - used
65+
/// by the agent's HTTP API.
6066
pub async fn get_blob_by_versioned_hash(versioned_hash: &str) -> Result<Value, Error> {
6167
let client = s3_client().await;
6268
let s3_bucket_name = get_env_var("S3_BUCKET_NAME").unwrap();
@@ -70,8 +76,7 @@ pub async fn get_blob_by_versioned_hash(versioned_hash: &str) -> Result<Value, E
7076
let res = serde_json::to_value(&data)?;
7177
Ok(res)
7278
}
73-
74-
pub async fn insert_block(block_id: u64, blobs: Vec<BlobInfo>) -> Result<(), Error> {
79+
pub(crate) async fn insert_block(block_id: u64, blobs: Vec<BlobInfo>) -> Result<(), Error> {
7580
let mut hashes: Vec<String> = Vec::new();
7681
for blob in blobs {
7782
if !hashes.contains(&blob.versioned_hash) {

src/core/server_handlers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
//! Module that handles the agent's HTTP API server
2-
//!
2+
//!
33
//! Endpoints:
44
//! - GET route: `/`
55
//! - GET blob's associated ANS-104 DataItem ID: `/v1/blob/:versioned_hash`
66
//! - GET indexer stats: `/v1/stats`
77
use crate::core::indexer::{get_indexer_stats, get_versioned_hash_value};
88
use axum::{extract::Path, response::Json};
99
use serde_json::Value;
10-
10+
/// Agent's server health check.
1111
pub async fn handle_route() -> &'static str {
1212
"load it up [^^]"
1313
}
14-
14+
/// Agent's server blob's metadata keys retrieval.
1515
pub async fn handle_get_blob(Path(versioned_hash): Path<String>) -> Json<Value> {
1616
let res = get_versioned_hash_value(&versioned_hash).await;
1717
Json(res.unwrap_or_else(|_| serde_json::json!({"error": "Blob not found"})))
1818
}
19-
19+
/// Agent's stats retrieval
2020
pub async fn handle_get_stats() -> Json<Value> {
2121
let res = get_indexer_stats().await;
2222
Json(res.unwrap_or_default())

src/core/types.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,34 @@
22
//! Data types mostly associated with the Ethereum blobs
33
use serde::{Deserialize, Serialize};
44

5+
/// Used by the agent's indexer to handle the
6+
/// versioned hash DB response.
57
#[derive(Debug, Serialize, Deserialize)]
68
pub struct VersionedHashOnly {
9+
/// Blob's versioned hash
710
pub versioned_hash: String,
811
}
9-
12+
/// Blob's main data structure. Represents the
13+
/// ANS-104 DataItem data field.
1014
#[derive(Debug, Serialize, Deserialize, Default)]
1115
pub struct BlobInfo {
16+
/// EIP-4844 tx's block number
1217
pub ethereum_block_number: u64,
18+
/// Blob's versioned hash
1319
pub versioned_hash: String,
20+
/// Blob's hex data field
1421
pub data: String,
1522
}
1623

1724
impl BlobInfo {
25+
/// Creates a BlobInfo instance from given struct field params.
1826
pub fn from(ethereum_block_number: u64, versioned_hash: String, data: String) -> Self {
1927
Self { ethereum_block_number, versioned_hash, data }
2028
}
2129
}
2230

2331
impl std::fmt::Display for BlobInfo {
32+
/// BlobInfo custom display formatted function
2433
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2534
write!(
2635
f,

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//! Blobscan Agent - Main application entry point.
2-
//!
2+
//!
33
//! This application serves as a bridge between Ethereum's EIP-4844 blob data
4-
//! served by blobscab.com and Load's HyperBEAM ~s3@1.0 device (temporal storage).
4+
//! served by blobscab.com and Load's HyperBEAM ~s3@1.0 device (temporal storage).
55
//! It continuously monitors Ethereum blocks for blob transactions, processes them
66
//! into ANS-104 DataItems, and stores them on Load's HyperBEAM S3 device for hybrid retrieval.
7-
//!
7+
//!
88
//! ## Architecture:
99
//! - HTTP API server for blob metadata retrieval and stats
10-
//! - Background indexer for continuous Ethereum block monitoring
10+
//! - Background indexer for continuous Ethereum block monitoring
1111
//! - HyperBEAM ~s3@1.0 storage integration with ANS-104 data format
1212
//! - Indexer's database PlanetScalefor blob metadata indexing
13-
//!
13+
//!
1414
//! ## API Endpoints:
1515
//! - `GET /` - Health check
1616
//! - `GET /v1/blob/:versioned_hash` - Get blob ANS-104 DataItem ID

0 commit comments

Comments
 (0)