1- use std :: time :: Duration ;
1+ use crate :: backend :: retry :: { retry_function , RetryError } ;
22use aligned_sdk:: common:: types:: VerificationData ;
3+ use std:: time:: Duration ;
34use tracing:: { info, warn} ;
4- use crate :: backend:: retry:: { retry_function, RetryError } ;
55
66#[ derive( Debug ) ]
77#[ allow( dead_code) ]
@@ -40,20 +40,22 @@ async fn get_aligned_batch_from_s3_retryable(
4040 . connect_timeout ( CONNECT_TIMEOUT_SECONDS )
4141 . timeout ( BATCH_DOWNLOAD_TIMEOUT_SECONDS )
4242 . build ( )
43- . map_err ( |e| RetryError :: Permanent ( GetBatchProofsError :: ReqwestClientFailed ( e. to_string ( ) ) ) ) ?;
44-
45- let response = client
46- . get ( & url)
47- . send ( )
48- . await
4943 . map_err ( |e| {
50- warn ! ( "Failed to send request to {}: {}" , url, e) ;
51- RetryError :: Transient ( GetBatchProofsError :: FetchingS3Batch ( e. to_string ( ) ) )
44+ RetryError :: Permanent ( GetBatchProofsError :: ReqwestClientFailed ( e. to_string ( ) ) )
5245 } ) ?;
5346
47+ let response = client. get ( & url) . send ( ) . await . map_err ( |e| {
48+ warn ! ( "Failed to send request to {}: {}" , url, e) ;
49+ RetryError :: Transient ( GetBatchProofsError :: FetchingS3Batch ( e. to_string ( ) ) )
50+ } ) ?;
51+
5452 if !response. status ( ) . is_success ( ) {
5553 let status_code = response. status ( ) . as_u16 ( ) ;
56- let reason = response. status ( ) . canonical_reason ( ) . unwrap_or ( "" ) . to_string ( ) ;
54+ let reason = response
55+ . status ( )
56+ . canonical_reason ( )
57+ . unwrap_or ( "" )
58+ . to_string ( ) ;
5759
5860 // Determine if the error is retryable based on status code
5961 let error = GetBatchProofsError :: StatusFailed ( ( status_code, reason) ) ;
@@ -69,20 +71,16 @@ async fn get_aligned_batch_from_s3_retryable(
6971 } ;
7072 }
7173
72- let bytes = response
73- . bytes ( )
74- . await
75- . map_err ( |e| {
76- warn ! ( "Failed to read response body from {}: {}" , url, e) ;
77- RetryError :: Transient ( GetBatchProofsError :: EmptyBody ( e. to_string ( ) ) )
78- } ) ?;
74+ let bytes = response. bytes ( ) . await . map_err ( |e| {
75+ warn ! ( "Failed to read response body from {}: {}" , url, e) ;
76+ RetryError :: Transient ( GetBatchProofsError :: EmptyBody ( e. to_string ( ) ) )
77+ } ) ?;
7978 let bytes: & [ u8 ] = bytes. iter ( ) . as_slice ( ) ;
8079
81- let data: Vec < VerificationData > = ciborium:: from_reader ( bytes)
82- . map_err ( |e| {
83- warn ! ( "Failed to deserialize batch data from {}: {}" , url, e) ;
84- RetryError :: Permanent ( GetBatchProofsError :: Deserialization ( e. to_string ( ) ) )
85- } ) ?;
80+ let data: Vec < VerificationData > = ciborium:: from_reader ( bytes) . map_err ( |e| {
81+ warn ! ( "Failed to deserialize batch data from {}: {}" , url, e) ;
82+ RetryError :: Permanent ( GetBatchProofsError :: Deserialization ( e. to_string ( ) ) )
83+ } ) ?;
8684
8785 Ok ( data)
8886}
0 commit comments