File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -98,11 +98,19 @@ pub struct Batcher {
9898 aggregator_fee_percentage_multiplier : u128 ,
9999 aggregator_gas_cost : u128 ,
100100
101- // Shared state (Mutex)
102- /// The general business rule is:
103- /// - User processing can be done in parallel unless a batch creation is happening
104- /// - Batch creation needs to be able to change all the states, so all processing
105- /// needs to be stopped, and all user_states locks need to be taken
101+
102+ // Shared state access:
103+ // Two kinds of threads interact with the shared state:
104+ // 1. User message processing threads (run in parallel)
105+ // 2. Batch creation thread (runs sequentially, includes failure recovery)
106+ //
107+ // Locking rules:
108+ // - To avoid deadlocks, always acquire `user_states` before `batch_state`.
109+ // - During failure recovery, restoring a valid state may require breaking this rule:
110+ // additional user locks might be acquired *after* the batch lock.
111+ // (See the `restore` algorithm in the `batch_queue` module.)
112+ //
113+ // Because of this exception, user message handling uses lock acquisition with timeouts.
106114 batch_state : Mutex < BatchState > ,
107115
108116 /// Flag to indicate when recovery is in progress
You can’t perform that action at this time.
0 commit comments