@@ -75,9 +75,9 @@ pub struct Batcher {
7575 s3_client : S3Client ,
7676 s3_bucket_name : String ,
7777 download_endpoint : String ,
78- s3_client_secondary : S3Client ,
79- s3_bucket_name_secondary : String ,
80- download_endpoint_secondary : String ,
78+ s3_client_secondary : Option < S3Client > ,
79+ s3_bucket_name_secondary : Option < String > ,
80+ download_endpoint_secondary : Option < String > ,
8181 eth_ws_url : String ,
8282 eth_ws_url_fallback : String ,
8383 batcher_signer : Arc < SignerMiddlewareT > ,
@@ -125,20 +125,22 @@ impl Batcher {
125125
126126 let s3_client = s3:: create_client ( s3_config_primary) . await ;
127127
128- // Secondary S3 configuration
129- let s3_config_secondary = s3:: S3Config {
130- access_key_id : env:: var ( "AWS_ACCESS_KEY_ID_SECONDARY" ) . ok ( ) ,
131- secret_access_key : env:: var ( "AWS_SECRET_ACCESS_KEY_SECONDARY" ) . ok ( ) ,
132- region : env:: var ( "AWS_REGION_SECONDARY" ) . ok ( ) ,
133- endpoint_url : env:: var ( "UPLOAD_ENDPOINT_SECONDARY" ) . ok ( ) ,
134- } ;
135-
136- let s3_bucket_name_secondary = env:: var ( "AWS_BUCKET_NAME_SECONDARY" )
137- . expect ( "AWS_BUCKET_NAME_SECONDARY not found in environment" ) ;
138- let download_endpoint_secondary = env:: var ( "DOWNLOAD_ENDPOINT_SECONDARY" )
139- . expect ( "DOWNLOAD_ENDPOINT_SECONDARY not found in environment" ) ;
128+ // Secondary S3 configuration (optional)
129+ let s3_bucket_name_secondary = env:: var ( "AWS_BUCKET_NAME_SECONDARY" ) . ok ( ) ;
130+ let download_endpoint_secondary = env:: var ( "DOWNLOAD_ENDPOINT_SECONDARY" ) . ok ( ) ;
140131
141- let s3_client_secondary = s3:: create_client ( s3_config_secondary) . await ;
132+ let s3_client_secondary = if s3_bucket_name_secondary. is_some ( ) && download_endpoint_secondary. is_some ( ) {
133+ let s3_config_secondary = s3:: S3Config {
134+ access_key_id : env:: var ( "AWS_ACCESS_KEY_ID_SECONDARY" ) . ok ( ) ,
135+ secret_access_key : env:: var ( "AWS_SECRET_ACCESS_KEY_SECONDARY" ) . ok ( ) ,
136+ region : env:: var ( "AWS_REGION_SECONDARY" ) . ok ( ) ,
137+ endpoint_url : env:: var ( "UPLOAD_ENDPOINT_SECONDARY" ) . ok ( ) ,
138+ } ;
139+ Some ( s3:: create_client ( s3_config_secondary) . await )
140+ } else {
141+ info ! ( "Secondary S3 configuration not found or incomplete. Operating with primary S3 only." ) ;
142+ None
143+ } ;
142144
143145 let config = ConfigFromYaml :: new ( config_file) ;
144146 // Ensure max_batch_bytes_size can at least hold one proof of max_proof_size,
@@ -1913,25 +1915,28 @@ impl Batcher {
19131915 warn ! ( "Failed to upload batch to primary S3" ) ;
19141916 }
19151917
1916- // Try secondary S3 upload
1917- if self
1918- . upload_batch_to_s3 (
1919- & self . s3_client_secondary ,
1920- batch_bytes,
1921- file_name,
1922- & self . s3_bucket_name_secondary ,
1923- )
1924- . await
1925- . is_ok ( )
1926- {
1927- let secondary_url = format ! ( "{}/{}" , self . download_endpoint_secondary, file_name) ;
1928- successful_urls. push ( secondary_url. clone ( ) ) ;
1929- info ! (
1930- "Successfully uploaded batch to secondary S3: {}" ,
1931- secondary_url
1932- ) ;
1933- } else {
1934- warn ! ( "Failed to upload batch to secondary S3" ) ;
1918+ // Try secondary S3 upload (if configured)
1919+ if let ( Some ( s3_client_secondary) , Some ( s3_bucket_name_secondary) , Some ( download_endpoint_secondary) ) =
1920+ ( & self . s3_client_secondary , & self . s3_bucket_name_secondary , & self . download_endpoint_secondary ) {
1921+ if self
1922+ . upload_batch_to_s3 (
1923+ s3_client_secondary,
1924+ batch_bytes,
1925+ file_name,
1926+ s3_bucket_name_secondary,
1927+ )
1928+ . await
1929+ . is_ok ( )
1930+ {
1931+ let secondary_url = format ! ( "{}/{}" , download_endpoint_secondary, file_name) ;
1932+ successful_urls. push ( secondary_url. clone ( ) ) ;
1933+ info ! (
1934+ "Successfully uploaded batch to secondary S3: {}" ,
1935+ secondary_url
1936+ ) ;
1937+ } else {
1938+ warn ! ( "Failed to upload batch to secondary S3" ) ;
1939+ }
19351940 }
19361941
19371942 // Update metrics with number of available data services
0 commit comments