Function balance_checkpoint

Source
fn balance_checkpoint<T: LazyBalance>(
    balance: &mut T::Balance,
) -> Result<(), ShareBalanceError>
Expand description

Advances the checkpoint on balance updates (mint/reap).

The checkpoint is a monotonically increasing counter that represents logical time. It is incremented whenever the balance changes, i.e., when the share price (bias) is updated which helps track when deposits were made relative to balance state changes.

This is mainly useful for handling drain scenarios. If a full reap (drain) occurs after a deposit, earlier receipts may no longer be meaningful. A drain resets the share price (bias) to zero, so during withdrawal the receipt’s original pricing context becomes outdated, even though the shares still exist.

The checkpoint and drain point (stored in both balance and receipt) allow withdrawals to efficiently detect and handle such cases.

This keeps withdrawal logic simple and O(1) while maintaining correctness across balance resets.