Function explore_balance_states

Source
fn explore_balance_states<T, M, G, F, H>(
    users: &[M::User],
    deposits: &[T::Asset],
    adjustments: &[T::Asset],
    subjects: &[T::Subject],
    max_depth: u32,
    allowed_bps: u32,
    allowed_diff: u32,
    overrides: Option<BalanceTraps<G, F>>,
    hasher: Option<H>,
    results: &mut BalanceModelResults<T, M>,
)
where T: LazyBalanceMarker + Clone, M: ManualBalanceModel<T> + BalanceStateHasher<T, M> + BalanceGuards<T, M> + Clone, T::Id: Default, T::Asset: From<T::Asset> + Into<T::Asset>, G: Fn(&BalanceState<T, M>, &BalanceOp<T, M>) -> bool, F: Fn(&BalanceState<T, M>, &BalanceOp<T, M>) -> bool, H: Fn(&BalanceState<T, M>) -> u64,
Expand description

Core state exploration engine for LazyBalance.

Performs breadth-first exploration over operation sequences, starting from an initial empty state.

-> [Deposit]   -> [Deposit, Mint] -> [Deposit, Mint, Withdraw]
-> [Mint]      -> [Mint, Reap]
-> [Reap]      -> ...
-> [Withdraw]  -> ...
-> [Drain]     -> ...

Exploration proceeds level by level:

  • all sequences of length n are explored before n+1
  • each step extends the current trace by one BalanceOp
  • guards / traps / flow determine whether a branch continues

At each step:

  • checks BalanceGuards::invariant on the current state
  • generates candidate operations (vector of BalanceOp)
  • filters using:
    • guard_{op}(...) || trap(...)
    • guard_flow_{op}(...) && trap_flow(...)

For each valid operation:

  • executes lazy model
  • applies manual model
  • updates state (receipts, trace)
  • evaluates withdrawal drift (compare_balances_values)

Uses:

  • visited set with BalanceStateHasher to avoid revisiting states
  • optional custom hasher for additional deduplication

Records:

  • errors (failures)
  • exits (drift beyond tolerance)
  • successful paths

This function defines the full execution semantics for:

  • guarded exploration
  • trap-based overrides
  • state-space traversal