/// Based on the query allocation of the canister and how much of it has
/// already been consumed in the current interval, returns the amount of
/// allocation that is still available for executing.
Based on the query allocation of the canister and how much of it has
already been consumed in the current interval, returns the amount of
allocation that is still available for executing.
Based on the query allocation of the canister and how much of it has already been consumed in the current interval returns the amount of allocation that is still available for executing .
pub(crate) fn allocation_before_execution(
        &mut self,
        canister: &CanisterState,
    ) -> QueryAllocation {
        let allocation_used = match self.allocations.get(&canister.canister_id()) {
            None => QueryAllocation::zero(),
            Some(allocation) => *allocation,
        };
        let allocation_available = QueryAllocation::default() - allocation_used;
        // Should not return the entire allocation for execution. This is
        // because if the message execution traps, then the Hypervisor deducts
        // the entire supplied allocation. This prevents the canister
        // from handling additional queries till the next purge interval. Hence,
        // set a smaller bound on how much cycles a single query can consume.
        std::cmp::min(allocation_available, QueryAllocation::max_per_message())
    }
pub ( crate ) fn allocation_before_execution ( & mut self , canister : & CanisterState , ) -> QueryAllocation { let allocation_used = match self . allocations . get ( & canister . canister_id ( ) ) { None => QueryAllocation :: zero ( ) , Some ( allocation ) => * allocation , } ; let allocation_available = QueryAllocation :: default ( ) - allocation_used ; // Should not return the entire allocation for execution. This is // because if the message execution traps, then the Hypervisor deducts // the entire supplied allocation. This prevents the canister // from handling additional queries till the next purge interval. Hence, // set a smaller bound on how much cycles a single query can consume. std :: cmp :: min ( allocation_available , QueryAllocation :: max_per_message ( ) ) }
Based on the query allocation of the canister and how much of it has
already been consumed in the current interval, returns the amount of
allocation that is still available for executing.
Based on the query allocation of the canister and how much of it has already been consumed in the current interval returns the amount of allocation that is still available for executing .
&mut self
canister
&CanisterState