Skip to content

Commit 99a6a37

Browse files
committed
feat: s3 service
1 parent ff12d58 commit 99a6a37

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

aggregation-mode/src/backend/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ pub struct ECDSAConfig {
1010
#[derive(Debug, Deserialize)]
1111
pub struct Config {
1212
pub eth_rpc_url: String,
13+
pub eth_ws_url: String,
1314
pub private_key: String,
1415
pub submit_proofs_every_secs: u64,
1516
pub max_proofs_in_queue: u16,
1617
pub proof_aggregation_service_address: String,
18+
pub aligned_service_manager_address: String,
1719
pub ecdsa: ECDSAConfig,
20+
pub bucket_name: String,
1821
}
1922

2023
impl Config {

aggregation-mode/src/backend/s3.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use aligned_sdk::core::types::VerificationData;
2+
use aws_config::{meta::region::RegionProviderChain, BehaviorVersion};
3+
use aws_sdk_s3::Client;
4+
use tracing::info;
5+
6+
pub struct S3Client {
7+
client: Client,
8+
bucket_name: String,
9+
}
10+
11+
pub enum GetBatchProofsError {
12+
Fetching,
13+
Deserialization,
14+
EmptyBody,
15+
}
16+
17+
impl S3Client {
18+
pub async fn new(bucket_name: String, endpoint_url: Option<String>) -> Self {
19+
let region_provider = RegionProviderChain::default_provider().or_else("us-east-2");
20+
let mut config = aws_config::defaults(BehaviorVersion::latest()).region(region_provider);
21+
if let Some(endpoint_url) = &endpoint_url {
22+
info!("Using custom endpoint: {}", endpoint_url);
23+
config = config.endpoint_url(endpoint_url);
24+
}
25+
let config = config.load().await;
26+
27+
let mut s3_config_builder = aws_sdk_s3::config::Builder::from(&config);
28+
if endpoint_url.is_some() {
29+
info!("Forcing path style for custom endpoint");
30+
s3_config_builder = s3_config_builder.force_path_style(true);
31+
}
32+
33+
let client = Client::from_conf(s3_config_builder.build());
34+
35+
Self {
36+
client,
37+
bucket_name,
38+
}
39+
}
40+
41+
pub async fn get_aligned_batch(
42+
&self,
43+
key: String,
44+
) -> Result<Vec<VerificationData>, GetBatchProofsError> {
45+
let result = self
46+
.client
47+
.get_object()
48+
.bucket(self.bucket_name.clone())
49+
.key(key)
50+
.send()
51+
.await
52+
.map_err(|_| GetBatchProofsError::Fetching)?;
53+
54+
let Some(bytes) = result.body.bytes() else {
55+
return Err(GetBatchProofsError::EmptyBody);
56+
};
57+
58+
let data: Vec<VerificationData> =
59+
ciborium::from_reader(bytes).map_err(|_| GetBatchProofsError::Deserialization)?;
60+
61+
Ok(data)
62+
}
63+
}

0 commit comments

Comments
 (0)