pub struct WithdrawQueue {
pub next_withdraw_to_execute: u64,
pub next_pending_withdrawal_id: u64,
/* private fields */
}Expand description
Withdrawal queue storage with FIFO ordering.
Maintains pending withdrawals keyed by monotonic IDs with escrow parity.
The queue uses a sorted Vec for efficient iteration and predictable serialization, with two
pointers to track the FIFO head and next ID to allocate.
§Invariants
pending_withdrawals.len() <= max_pending_withdrawals <= MAX_PENDINGnext_withdraw_to_execute <= next_pending_withdrawal_id- If
pending_withdrawals.len() > 0, thenpending_withdrawalscontainsnext_withdraw_to_execute - FIFO withdrawal ordering; no skipping head
cached_total_escrow == sum(pending_withdrawals.values().map(|w| w.escrow_shares))cached_total_expected == sum(pending_withdrawals.values().map(|w| w.expected_assets))
Fields§
§next_withdraw_to_execute: u64ID of the next withdrawal to execute (queue head).
next_pending_withdrawal_id: u64Next ID to allocate for new withdrawals (monotonic, never decremented).
Implementations§
Source§impl WithdrawQueue
impl WithdrawQueue
Sourcepub fn with_state<I>(
pending_withdrawals: I,
next_withdraw_to_execute: u64,
next_pending_withdrawal_id: u64,
) -> Self
pub fn with_state<I>( pending_withdrawals: I, next_withdraw_to_execute: u64, next_pending_withdrawal_id: u64, ) -> Self
Create a queue with initial state (for testing or recovery).
pub fn pending_withdrawals(&self) -> &PendingWithdrawals
Sourcepub fn can_enqueue(&self, max_pending: u32) -> bool
pub fn can_enqueue(&self, max_pending: u32) -> bool
Sourcepub fn enqueue(
&mut self,
owner: Address,
receiver: Address,
escrow_shares: u128,
expected_assets: u128,
requested_at_ns: TimestampNs,
max_pending: u32,
) -> Result<u64, QueueError>
pub fn enqueue( &mut self, owner: Address, receiver: Address, escrow_shares: u128, expected_assets: u128, requested_at_ns: TimestampNs, max_pending: u32, ) -> Result<u64, QueueError>
Enqueue a new pending withdrawal.
Convenience wrapper that constructs a PendingWithdrawal and delegates
to enqueue_withdrawal.
Sourcepub fn enqueue_withdrawal(
&mut self,
withdrawal: PendingWithdrawal,
max_pending: u32,
) -> Result<u64, QueueError>
pub fn enqueue_withdrawal( &mut self, withdrawal: PendingWithdrawal, max_pending: u32, ) -> Result<u64, QueueError>
Enqueue a pre-constructed pending withdrawal.
Allocates a new monotonic ID and inserts the withdrawal at the tail.
§Returns
Ok(id) with the allocated withdrawal ID, or Err(QueueError) if full.
Sourcepub fn head(&self) -> Option<(u64, &PendingWithdrawal)>
pub fn head(&self) -> Option<(u64, &PendingWithdrawal)>
Get the head of the queue without removing it.
§Returns
Some((id, &withdrawal)) if non-empty, None if empty.
Sourcepub fn dequeue(&mut self) -> Option<(u64, PendingWithdrawal)>
pub fn dequeue(&mut self) -> Option<(u64, PendingWithdrawal)>
Dequeue and return the head of the queue (FIFO).
Removes the head and advances next_withdraw_to_execute to the next
available ID in the queue (or to next_pending_withdrawal_id if empty).
§Returns
Some((id, withdrawal)) if non-empty, None if empty.
Sourcepub fn get(&self, id: u64) -> Option<&PendingWithdrawal>
pub fn get(&self, id: u64) -> Option<&PendingWithdrawal>
Sourcepub fn iter(&self) -> impl Iterator<Item = (u64, &PendingWithdrawal)>
pub fn iter(&self) -> impl Iterator<Item = (u64, &PendingWithdrawal)>
Iterate over all pending withdrawals in FIFO order.
§Returns
Iterator yielding (id, &withdrawal) pairs in order.
Sourcepub fn check_invariants(&self) -> bool
pub fn check_invariants(&self) -> bool
Check invariants for the withdrawal queue.
Validates:
next_withdraw_to_execute <= next_pending_withdrawal_id- If non-empty, head ID exists in the map
- Cached totals match computed totals
§Returns
true if all invariants hold.
Sourcepub fn check_invariants_with_max(&self, max_pending: u32) -> bool
pub fn check_invariants_with_max(&self, max_pending: u32) -> bool
Sourcepub fn status(&self) -> QueueStatus
pub fn status(&self) -> QueueStatus
Get total escrowed shares across all pending withdrawals.
Returns cached value in O(1) time.
§Returns
Total escrow shares.
Sourcepub fn total_expected_assets(&self) -> u128
pub fn total_expected_assets(&self) -> u128
Get total expected assets across all pending withdrawals.
Returns cached value in O(1) time.
§Returns
Total expected assets.
Trait Implementations§
Source§impl BorshDeserialize for WithdrawQueue
impl BorshDeserialize for WithdrawQueue
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSchema for WithdrawQueue
impl BorshSchema for WithdrawQueue
Source§fn declaration() -> Declaration
fn declaration() -> Declaration
Source§fn add_definitions_recursively(
definitions: &mut BTreeMap<Declaration, Definition>,
)
fn add_definitions_recursively( definitions: &mut BTreeMap<Declaration, Definition>, )
Source§impl BorshSerialize for WithdrawQueue
impl BorshSerialize for WithdrawQueue
Source§impl Clone for WithdrawQueue
impl Clone for WithdrawQueue
Source§fn clone(&self) -> WithdrawQueue
fn clone(&self) -> WithdrawQueue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more