penumbra_sdk_dex/component/circuit_breaker/execution.rs
1/// The execution circuit breaker meters the number of operations (search and execution)
2/// performed to fulfill a batch swap.
3///
4/// The Dex component MUST call `CircuitBreaker::exceed_limits` before an execution round.
5///
6/// Note that in practice, this means that a batch swap can result in a partial fill
7/// even if there were enough liquidity to fulfill all of it.
8#[derive(Debug, Clone)]
9pub(crate) struct ExecutionCircuitBreaker {
10 /// The current number of operations performed.
11 pub counter: u32,
12 /// The maximum number of operations allowed.
13 pub max: u32,
14}
15
16impl ExecutionCircuitBreaker {
17 pub fn new(max: u32) -> Self {
18 Self { max, counter: 0 }
19 }
20
21 pub fn increment(&mut self) {
22 self.counter += 1;
23 }
24
25 pub fn exceeded_limits(&self) -> bool {
26 self.counter >= self.max
27 }
28}