@@ -34,14 +34,13 @@ mod config;
3434mod eth;
3535pub mod gnark;
3636pub mod halo2;
37+ pub mod mina;
3738pub mod risc_zero;
3839pub mod s3;
3940pub mod sp1;
4041pub mod types;
4142mod zk_utils;
4243
43- const S3_BUCKET_NAME : & str = "storage.alignedlayer.com" ;
44-
4544pub struct Batcher {
4645 s3_client : S3Client ,
4746 eth_ws_provider : Provider < Ws > ,
@@ -306,7 +305,7 @@ impl Batcher {
306305 {
307306 let mut last_uploaded_batch_block = self . last_uploaded_batch_block . lock ( ) . await ;
308307 self . submit_batch ( & batch_bytes, & batch_merkle_tree. root )
309- . await ;
308+ . await ? ;
310309 // update last uploaded batch block
311310 * last_uploaded_batch_block = block_number;
312311 }
@@ -341,26 +340,52 @@ impl Batcher {
341340 }
342341
343342 /// Post batch to s3 and submit new task to Ethereum
344- async fn submit_batch ( & self , batch_bytes : & [ u8 ] , batch_merkle_root : & [ u8 ; 32 ] ) {
343+ async fn submit_batch (
344+ & self ,
345+ batch_bytes : & [ u8 ] ,
346+ batch_merkle_root : & [ u8 ; 32 ] ,
347+ ) -> Result < ( ) , BatcherError > {
348+ let s3_bucket_name: String = std:: env:: var ( "AWS_BUCKET_NAME" )
349+ . map_err ( |e| BatcherError :: S3EnvVariableError ( "AWS_BUCKET_NAME" . to_owned ( ) , e) ) ?;
350+ let s3_bucket_name_is_domain = std:: env:: var ( "AWS_BUCKET_NAME_IS_DOMAIN" ) . is_ok ( ) ;
351+
345352 let s3_client = self . s3_client . clone ( ) ;
346353 let batch_merkle_root_hex = hex:: encode ( batch_merkle_root) ;
347354 info ! ( "Batch merkle root: {}" , batch_merkle_root_hex) ;
348355 let file_name = batch_merkle_root_hex. clone ( ) + ".json" ;
349356
350357 info ! ( "Uploading batch to S3..." ) ;
351- s3:: upload_object ( & s3_client, S3_BUCKET_NAME , batch_bytes. to_vec ( ) , & file_name)
352- . await
353- . expect ( "Failed to upload object to S3" ) ;
358+ s3:: upload_object (
359+ & s3_client,
360+ & s3_bucket_name,
361+ batch_bytes. to_vec ( ) ,
362+ & file_name,
363+ )
364+ . await
365+ . expect ( "Failed to upload object to S3" ) ;
354366
355367 info ! ( "Batch sent to S3 with name: {}" , file_name) ;
356368
357369 info ! ( "Uploading batch to contract" ) ;
358370 let service_manager = & self . service_manager ;
359- let batch_data_pointer = "https://" . to_owned ( ) + S3_BUCKET_NAME + "/" + & file_name;
371+
372+ let batch_data_pointer = if s3_bucket_name_is_domain {
373+ "https://" . to_owned ( ) + & s3_bucket_name + "/" + & file_name
374+ } else {
375+ let s3_region: String = std:: env:: var ( "AWS_REGION" )
376+ . map_err ( |e| BatcherError :: S3EnvVariableError ( "AWS_REGION" . to_owned ( ) , e) ) ?;
377+ "https://" . to_owned ( )
378+ + & s3_bucket_name
379+ + ".s3."
380+ + & s3_region
381+ + ".amazonaws.com/"
382+ + & file_name
383+ } ;
360384 match eth:: create_new_task ( service_manager, * batch_merkle_root, batch_data_pointer) . await {
361385 Ok ( _) => info ! ( "Batch verification task created on Aligned contract" ) ,
362386 Err ( e) => error ! ( "Failed to create batch verification task: {}" , e) ,
363387 }
388+ Ok ( ( ) )
364389 }
365390}
366391/// Await for the `BatchVerified` event emitted by the Aligned contract and then send responses.
0 commit comments