Skip to content

Commit 93b1115

Browse files
committed
fear: migrate from PS to object storage model
1 parent f92343e commit 93b1115

File tree

11 files changed

+1954
-1270
lines changed

11 files changed

+1954
-1270
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ eyre = "0.6.12"
1818
brotli = "7.0.0"
1919
serde = "1.0.215"
2020
serde_json = "1.0.133"
21-
planetscale-driver = "0.5.1"
2221
dotenv = "0.15.0"
23-
shuttle-runtime = "0.50.0"
24-
shuttle-axum = "0.50.0"
2522
axum = "0.7.9"
23+
tokio-util = "0.7"
24+
tower = "0.4"
2625
reqwest = {version = "0.12.12", features=["json"]}
2726
anyhow = "1.0.98"
27+
bundles_rs = { git = "https://github.com/loadnetwork/bundles-rs.git", branch = "main"}
28+
aws-config = { version= "1.8.3", features = ["behavior-version-latest"] }
29+
aws-sdk-s3= { version = "1.100.0", features = ["rt-tokio"] }

Shuttle.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,23 @@ use {
33
std::sync::Arc,
44
tokio::sync::RwLock,
55
utils::{
6-
blobscan::{get_blobs_of_block, insert_block},
6+
blobscan::get_blobs_of_block,
77
constants::FIRST_ETH_L1_EIP4844_BLOCK,
88
eth::Ethereum,
9-
planetscale::get_latest_block_id,
9+
s3::{get_latest_block_id, insert_block},
1010
server_handlers::{handle_get_blob, handle_get_stats, handle_weave_gm},
11+
env_var::load_env_vars,
1112
},
1213
};
1314

1415
mod utils;
1516

16-
#[shuttle_runtime::main]
17-
async fn main(
18-
#[shuttle_runtime::Secrets] secrets: shuttle_runtime::SecretStore,
19-
) -> shuttle_axum::ShuttleAxum {
20-
// load secrets from Shuttle.toml into env var;
21-
secrets.into_iter().for_each(|(key, val)| {
22-
std::env::set_var(key, val);
23-
});
17+
#[tokio::main]
18+
async fn main() {
19+
load_env_vars();
2420
let router = Router::new()
2521
.route("/", get(handle_weave_gm))
26-
.route("/v1/blob/:versioned_hash", get(handle_get_blob))
22+
.route("/v1/blob/{versioned_hash}", get(handle_get_blob))
2723
.route("/v1/stats", get(handle_get_stats));
2824

2925
let block_number = Ethereum::get_latest_eth_block().await.unwrap();
@@ -45,10 +41,11 @@ async fn main(
4541
match blobs {
4642
Ok(blobs) => {
4743
println!("INSERTING: {:?} BLOBS", blobs.len());
44+
println!("BLOBS: {:?}\n\n\n", blobs);
4845
let res = insert_block(target_block_id, blobs).await;
4946
match res {
50-
Ok(res) => latest_archived_block += 1,
51-
_ => eprintln!("error updating planetscale"),
47+
Ok(_) => latest_archived_block += 1,
48+
Err(e) => eprintln!("error updating s3: {}", e),
5249
}
5350
}
5451
Err(e) => {
@@ -69,5 +66,7 @@ async fn main(
6966
}
7067
});
7168

72-
Ok(router.into())
69+
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
70+
println!("Server running on http://0.0.0.0:3000");
71+
axum::serve(listener, router).await.unwrap();
7372
}

src/utils/blobscan.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use {
22
crate::utils::{
33
env_var::get_env_var,
4-
planetscale::{ps_archive_block, ps_get_all_versioned_hashes_paginated},
54
types::BlobInfo,
6-
wvm::send_wvm_calldata,
75
},
8-
eyre::{eyre, Error, Result},
6+
eyre::{Error, Result},
97
reqwest,
108
serde_json::{self, Value},
11-
std::io::{Read, Write},
129
};
1310

1411
pub async fn get_blobs_versioned_hashes_of_block(
@@ -80,37 +77,7 @@ pub async fn get_blobs_of_block(block_id: u32) -> Result<Vec<BlobInfo>> {
8077

8178
pub fn serialize_blobscan_block(block: &BlobInfo) -> Result<Vec<u8>> {
8279
let data = serde_json::to_vec(&block)?;
83-
let compressed_data = brotli_compress(&data);
84-
Ok(compressed_data)
85-
}
86-
87-
pub async fn insert_block(block_id: u32, blobs: Vec<BlobInfo>) -> Result<(), Error> {
88-
for blob in blobs {
89-
let wvm_data_input = serialize_blobscan_block(&blob)?;
90-
let wvm_txid = send_wvm_calldata(wvm_data_input).await.unwrap();
91-
let _res = ps_archive_block(&block_id, &wvm_txid, &blob.versioned_hash, &blob.data)
92-
.await
93-
.unwrap();
94-
let _send_to_blobscan = send_blob_to_blobscan(&blob.versioned_hash).await.unwrap();
95-
}
96-
97-
Ok(())
98-
}
99-
100-
fn brotli_compress(input: &[u8]) -> Vec<u8> {
101-
let mut writer = brotli::CompressorWriter::new(Vec::new(), 4096, 11, 22);
102-
writer.write_all(input).unwrap();
103-
writer.into_inner()
104-
}
105-
106-
fn brotli_decompress(input: Vec<u8>) -> Vec<u8> {
107-
let mut decompressed_data = Vec::new();
108-
let mut decompressor = brotli::Decompressor::new(input.as_slice(), 4096); // 4096 is the buffer size
109-
110-
decompressor
111-
.read_to_end(&mut decompressed_data)
112-
.expect("Decompression failed");
113-
decompressed_data
80+
Ok(data)
11481
}
11582

11683
pub async fn send_blob_to_blobscan(blob_hash: &str) -> Result<(), Error> {

src/utils/env_var.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use {dotenv::dotenv, std::env};
22

3-
pub fn get_env_var(key: &str) -> Result<String, env::VarError> {
3+
pub fn load_env_vars() {
44
dotenv().ok();
5+
}
6+
7+
pub fn get_env_var(key: &str) -> Result<String, env::VarError> {
58
match env::var(key) {
69
Ok(val) => Ok(val),
710
Err(e) => Err(e),

src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod blobscan;
22
pub mod constants;
33
pub mod env_var;
44
pub mod eth;
5-
pub mod planetscale;
5+
pub mod s3;
66
pub mod server_handlers;
77
pub mod types;
88
pub mod wvm;

src/utils/planetscale.rs

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)