@@ -223,39 +223,33 @@ impl BatchState {
223223 } )
224224 }
225225
226- // removes a proof from a user state
227- pub ( crate ) fn remove_entry_from_user_state ( & mut self , entry : & BatchQueueEntry ) {
228- let addr = entry. sender ;
229-
230- if entry. nonced_verification_data . nonce == U256 :: zero ( ) {
231- self . user_states . remove ( & addr) ;
232- return ;
233- }
234- let nonce = entry. nonced_verification_data . nonce - U256 :: one ( ) ;
235-
236- match self
226+ /// Updates or removes a user's state when their latest proof entry is removed from the batch queue.
227+ ///
228+ /// If the user has no other proofs remaining in the queue, their state is removed entirely.
229+ /// Otherwise, the user's state is updated to reflect the next most recent entry in the queue.
230+ ///
231+ /// Note: The given `removed_entry` must be the most recent (latest or highest nonce) entry for the user in the queue.
232+ pub ( crate ) fn update_user_state_on_entry_removal ( & mut self , removed_entry : & BatchQueueEntry ) {
233+ let addr = removed_entry. sender ;
234+
235+ let last_max_fee_limit = match self
237236 . batch_queue
238237 . iter ( )
239- . map ( |( e, _) | e)
240- . find ( |e| e . sender == addr && e . nonced_verification_data . nonce == nonce )
238+ . filter ( |( e, _) | e. sender == addr )
239+ . last ( )
241240 {
242- Some ( last_entry) => {
243- if let Entry :: Occupied ( mut user_state) = self . user_states . entry ( addr) {
244- user_state. get_mut ( ) . proofs_in_batch -= 1 ;
245- user_state. get_mut ( ) . nonce -= U256 :: one ( ) ;
246- user_state. get_mut ( ) . total_fees_in_queue -= U256 :: one ( ) ;
247- user_state. get_mut ( ) . last_max_fee_limit =
248- last_entry. nonced_verification_data . max_fee ;
249- }
250- }
241+ Some ( ( last_entry, _) ) => last_entry. nonced_verification_data . max_fee ,
251242 None => {
252- if let Entry :: Occupied ( mut user_state) = self . user_states . entry ( addr) {
253- user_state. get_mut ( ) . proofs_in_batch = 0 ;
254- user_state. get_mut ( ) . nonce -= U256 :: one ( ) ;
255- user_state. get_mut ( ) . total_fees_in_queue = U256 :: zero ( ) ;
256- user_state. get_mut ( ) . last_max_fee_limit = U256 :: max_value ( ) ;
257- }
243+ self . user_states . remove ( & addr) ;
244+ return ;
258245 }
246+ } ;
247+
248+ if let Entry :: Occupied ( mut user_state) = self . user_states . entry ( addr) {
249+ user_state. get_mut ( ) . proofs_in_batch -= 1 ;
250+ user_state. get_mut ( ) . nonce -= U256 :: one ( ) ;
251+ user_state. get_mut ( ) . total_fees_in_queue -= U256 :: one ( ) ;
252+ user_state. get_mut ( ) . last_max_fee_limit = last_max_fee_limit;
259253 }
260254 }
261255
0 commit comments