@@ -730,45 +730,48 @@ impl Batcher {
730730 return Ok ( ( ) ) ;
731731 }
732732
733- let cached_user_nonce = batch_state_lock. get_user_nonce ( & addr) . await ;
734- let Some ( expected_nonce) = cached_user_nonce else {
735- error ! ( "Failed to get cached user nonce: User not found in user states, but it should have been already inserted" ) ;
736- std:: mem:: drop ( batch_state_lock) ;
737- send_message (
738- ws_conn_sink. clone ( ) ,
739- SubmitProofResponseMessage :: AddToBatchError ,
740- )
741- . await ;
742- self . metrics . user_error ( & [ "batcher_state_error" , "" ] ) ;
743- return Ok ( ( ) ) ;
744- } ;
745-
746- if expected_nonce < msg_nonce {
747- std:: mem:: drop ( batch_state_lock) ;
748- warn ! ( "Invalid nonce for address {addr}, expected nonce: {expected_nonce:?}, received nonce: {msg_nonce:?}" ) ;
749- send_message (
750- ws_conn_sink. clone ( ) ,
751- SubmitProofResponseMessage :: InvalidNonce ,
752- )
753- . await ;
754- self . metrics . user_error ( & [ "invalid_nonce" , "" ] ) ;
755- return Ok ( ( ) ) ;
756- }
733+ if self . has_to_pay ( & addr) {
734+ let cached_user_nonce = batch_state_lock. get_user_nonce ( & addr) . await ;
757735
758- // In this case, the message might be a replacement one. If it is valid,
759- // we replace the old entry with the new from the replacement message.
760- if expected_nonce > msg_nonce {
761- info ! ( "Possible replacement message received: Expected nonce {expected_nonce:?} - message nonce: {msg_nonce:?}" ) ;
762- self . handle_replacement_message (
763- batch_state_lock,
764- nonced_verification_data,
765- ws_conn_sink. clone ( ) ,
766- client_msg. signature ,
767- addr,
768- )
769- . await ;
736+ let Some ( expected_nonce) = cached_user_nonce else {
737+ error ! ( "Failed to get cached user nonce: User not found in user states, but it should have been already inserted" ) ;
738+ std:: mem:: drop ( batch_state_lock) ;
739+ send_message (
740+ ws_conn_sink. clone ( ) ,
741+ SubmitProofResponseMessage :: AddToBatchError ,
742+ )
743+ . await ;
744+ self . metrics . user_error ( & [ "batcher_state_error" , "" ] ) ;
745+ return Ok ( ( ) ) ;
746+ } ;
770747
771- return Ok ( ( ) ) ;
748+ if expected_nonce < msg_nonce {
749+ std:: mem:: drop ( batch_state_lock) ;
750+ warn ! ( "Invalid nonce for address {addr}, expected nonce: {expected_nonce:?}, received nonce: {msg_nonce:?}" ) ;
751+ send_message (
752+ ws_conn_sink. clone ( ) ,
753+ SubmitProofResponseMessage :: InvalidNonce ,
754+ )
755+ . await ;
756+ self . metrics . user_error ( & [ "invalid_nonce" , "" ] ) ;
757+ return Ok ( ( ) ) ;
758+ }
759+
760+ // In this case, the message might be a replacement one. If it is valid,
761+ // we replace the old entry with the new from the replacement message.
762+ if expected_nonce > msg_nonce {
763+ info ! ( "Possible replacement message received: Expected nonce {expected_nonce:?} - message nonce: {msg_nonce:?}" ) ;
764+ self . handle_replacement_message (
765+ batch_state_lock,
766+ nonced_verification_data,
767+ ws_conn_sink. clone ( ) ,
768+ client_msg. signature ,
769+ addr,
770+ )
771+ . await ;
772+
773+ return Ok ( ( ) ) ;
774+ }
772775 }
773776
774777 // We check this after replacement logic because if user wants to replace a proof, their
0 commit comments