/// Implements memory limits verification for pushing a canister-to-canister
/// message into the induction pool of `queues`.
///
/// Returns `StateError::OutOfMemory` if pushing the message would require more
/// memory than `queues_available_memory.min(subnet_available_memory)`.
///
/// `subnet_available_memory` is updated to reflect the change in memory usage
/// after a successful push; and left unmodified if the push failed.
///
/// See `CanisterQueues::push_input()` for further details.
Implements memory limits verification for pushing a canister-to-canister
message into the induction pool of `queues`.



`subnet_available_memory` is updated to reflect the change in memory usage
after a successful push; and left unmodified if the push failed.


Implements memory limits verification for pushing a canister - to - canister message into the induction pool of ` queues ` . ` subnet_available_memory ` is updated to reflect the change in memory usage after a successful push ; and left unmodified if the push failed .
pub(crate) fn push_input(
    queues: &mut CanisterQueues,
    index: QueueIndex,
    msg: RequestOrResponse,
    queues_available_memory: i64,
    subnet_available_memory: &mut i64,
    own_subnet_type: SubnetType,
    input_queue_type: InputQueueType,
) -> Result<(), (StateError, RequestOrResponse)> {
    if !ENFORCE_MESSAGE_MEMORY_USAGE || own_subnet_type == SubnetType::System {
        return queues.push_input(index, msg, input_queue_type);
    }
    let available_memory = queues_available_memory.min(*subnet_available_memory);
    if let Err(required_memory) = can_push(&msg, available_memory) {
        return Err((
            StateError::OutOfMemory {
                requested: NumBytes::new(required_memory as u64),
                available: available_memory,
            },
            msg,
        ));
    }
    // Adjust `subnet_available_memory` by `memory_usage_before -
    // memory_usage_after`. Defer to `CanisterQueues` for the accounting, to avoid
    // duplication (and the possibility of divergence).
    *subnet_available_memory += queues.memory_usage() as i64;
    let res = queues.push_input(index, msg, input_queue_type);
    *subnet_available_memory -= queues.memory_usage() as i64;
    res
}
pub ( crate ) fn push_input ( queues : & mut CanisterQueues , index : QueueIndex , msg : RequestOrResponse , queues_available_memory : i64 , subnet_available_memory : & mut i64 , own_subnet_type : SubnetType , input_queue_type : InputQueueType , ) -> Result < ( ) , ( StateError , RequestOrResponse ) > { if ! ENFORCE_MESSAGE_MEMORY_USAGE || own_subnet_type == SubnetType :: System { return queues . push_input ( index , msg , input_queue_type ) ; } let available_memory = queues_available_memory . min ( * subnet_available_memory ) ; if let Err ( required_memory ) = can_push ( & msg , available_memory ) { return Err ( ( StateError :: OutOfMemory { requested : NumBytes :: new ( required_memory as u64 ) , available : available_memory , } , msg , ) ) ; } // Adjust `subnet_available_memory` by `memory_usage_before - // memory_usage_after`. Defer to `CanisterQueues` for the accounting, to avoid // duplication (and the possibility of divergence). * subnet_available_memory += queues . memory_usage ( ) as i64 ; let res = queues . push_input ( index , msg , input_queue_type ) ; * subnet_available_memory -= queues . memory_usage ( ) as i64 ; res }
Implements memory limits verification for pushing a canister-to-canister
message into the induction pool of `queues`.
Implements memory limits verification for pushing a canister - to - canister message into the induction pool of ` queues ` .
queues
&mut CanisterQueues
index
QueueIndex
msg
RequestOrResponse
queues_available_memory
i64
subnet_available_memory
&mut i64
own_subnet_type
SubnetType
input_queue_type
InputQueueType