@@ -395,6 +395,7 @@ impl AptosDataClient {
395395 T : TryFrom < StorageServiceResponse , Error = E > ,
396396 E : Into < Error > ,
397397 {
398+ // Select a peer to service the request
398399 let peer = self . choose_peer_for_request ( & request) . map_err ( |error| {
399400 debug ! (
400401 ( LogSchema :: new( LogEntry :: StorageServiceRequest )
@@ -404,7 +405,8 @@ impl AptosDataClient {
404405 ) ;
405406 error
406407 } ) ?;
407- let _timer = start_request_timer ( & metrics:: REQUEST_LATENCIES , & request. get_label ( ) , peer) ;
408+
409+ // Send the request to the peer and transform the response
408410 self . send_request_to_peer_and_decode ( peer, request, request_timeout_ms)
409411 . await
410412 }
@@ -420,13 +422,29 @@ impl AptosDataClient {
420422 T : TryFrom < StorageServiceResponse , Error = E > ,
421423 E : Into < Error > ,
422424 {
425+ // Start the timer for the request
426+ let timer = start_request_timer ( & metrics:: REQUEST_LATENCIES , & request. get_label ( ) , peer) ;
427+
428+ // Get the response from the peer
423429 let response = self
424430 . send_request_to_peer ( peer, request. clone ( ) , request_timeout_ms)
425- . await ? ;
431+ . await ;
426432
427- let ( context, storage_response) = response. into_parts ( ) ;
433+ // If an error occurred, stop the timer (without updating the metrics)
434+ // and return the error. Otherwise, stop the timer and update the metrics.
435+ let storage_response = match response {
436+ Ok ( storage_response) => {
437+ timer. stop_and_record ( ) ; // Update the latency metrics
438+ storage_response
439+ } ,
440+ Err ( error) => {
441+ timer. stop_and_discard ( ) ; // Discard the timer without updating the metrics
442+ return Err ( error) ;
443+ } ,
444+ } ;
428445
429446 // Ensure the response obeys the compression requirements
447+ let ( context, storage_response) = storage_response. into_parts ( ) ;
430448 if request. use_compression && !storage_response. is_compressed ( ) {
431449 return Err ( Error :: InvalidResponse ( format ! (
432450 "Requested compressed data, but the response was uncompressed! Response: {:?}" ,
@@ -439,10 +457,10 @@ impl AptosDataClient {
439457 ) ) ) ;
440458 }
441459
442- // try to convert the storage service enum into the exact variant we're expecting.
460+ // Try to convert the storage service enum into the exact variant we're expecting
443461 match T :: try_from ( storage_response) {
444462 Ok ( new_payload) => Ok ( Response :: new ( context, new_payload) ) ,
445- // if the variant doesn't match what we're expecting, report the issue.
463+ // If the variant doesn't match what we're expecting, report the issue
446464 Err ( err) => {
447465 context
448466 . response_callback
0 commit comments