@@ -84,19 +84,21 @@ pub struct Batcher {
8484 payment_service_fallback : BatcherPaymentService ,
8585 service_manager : ServiceManager ,
8686 service_manager_fallback : ServiceManager ,
87- /// Holds both the user state and the proofs queue.
87+ /// Shared state containing both the user data and the proofs queue.
8888 ///
89- /// We should consider splitting the user state and the queue into separate mutexes
90- /// to improve concurrency.
89+ /// This state is accessed concurrently by the proof messages handler
90+ /// and the batches builder. Any mutation typically consists of:
91+ /// 1. Adding and/or removing a proof from the queue.
92+ /// 2. Updating the corresponding user state based on 1.
93+ ///
94+ /// The `batch_state` lock MUST be held for the full duration of both steps
95+ /// to ensure consistency in the state.
9196 batch_state : Mutex < BatchState > ,
92-
93- /// A map of per-user mutexes used to synchronize proof processing.
94- /// It allows us to mutate the users state atomically,
95- /// while avoiding the need to lock the entire [`batch_state`] structure.
97+ /// A map of per-user mutexes.
9698 ///
97- /// During batch building, the process also locks these per-user mutexes
98- /// (after acquiring [`building_batch_mutex`]) to ensure that all ongoing
99- /// proof messages complete and the state remains consistent .
99+ /// It allows us to synchronize the processing of proof messages
100+ /// per user ensuring the state is mutated atomically between each user,
101+ /// while avoiding the need to lock the entire [`batch_state`] structure .
100102 user_proof_processing_mutexes : Mutex < HashMap < Address , Arc < Mutex < ( ) > > > > ,
101103 min_block_interval : u64 ,
102104 transaction_wait_timeout : u64 ,
0 commit comments