Skip to content

Commit 1d665d8

Browse files
committed
add docs
1 parent f846b69 commit 1d665d8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crates/batcher/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)