@@ -877,9 +877,25 @@ impl Batcher {
877877 let is_user_in_state = self . user_states . read ( ) . await . contains_key ( & addr) ;
878878
879879 if !is_user_in_state {
880+ // If the user state was not present, we need to get the nonce from the Ethereum contract
881+ let ethereum_user_nonce = match self . get_user_nonce_from_ethereum ( addr) . await {
882+ Ok ( ethereum_user_nonce) => ethereum_user_nonce,
883+ Err ( e) => {
884+ error ! (
885+ "Failed to get user nonce from Ethereum for address {addr:?}. Error: {e:?}"
886+ ) ;
887+ send_message (
888+ ws_conn_sink. clone ( ) ,
889+ SubmitProofResponseMessage :: EthRpcError ,
890+ )
891+ . await ;
892+ self . metrics . user_error ( & [ "eth_rpc_error" , "" ] ) ;
893+ return Ok ( ( ) ) ;
894+ }
895+ } ;
880896 debug ! ( "User state for address {addr:?} not found, creating a new one" ) ;
881897 // We add a dummy user state to grab a lock on the user state
882- let dummy_user_state = UserState :: new ( U256 :: zero ( ) ) ;
898+ let dummy_user_state = UserState :: new ( ethereum_user_nonce ) ;
883899 self . user_states
884900 . write ( )
885901 . await
@@ -907,27 +923,6 @@ impl Batcher {
907923 return Ok ( ( ) ) ;
908924 } ;
909925
910- // If the user state was not present, we need to get the nonce from the Ethereum contract and update the dummy user state
911- if !is_user_in_state {
912- let ethereum_user_nonce = match self . get_user_nonce_from_ethereum ( addr) . await {
913- Ok ( ethereum_user_nonce) => ethereum_user_nonce,
914- Err ( e) => {
915- error ! (
916- "Failed to get user nonce from Ethereum for address {addr:?}. Error: {e:?}"
917- ) ;
918- send_message (
919- ws_conn_sink. clone ( ) ,
920- SubmitProofResponseMessage :: EthRpcError ,
921- )
922- . await ;
923- self . metrics . user_error ( & [ "eth_rpc_error" , "" ] ) ;
924- return Ok ( ( ) ) ;
925- }
926- } ;
927- // Update the dummy user state with the correct nonce
928- user_state_guard. nonce = ethereum_user_nonce;
929- }
930-
931926 // * ---------------------------------------------------*
932927 // * Perform validations over user state *
933928 // * ---------------------------------------------------*
0 commit comments