pub fn charge_canister_for_resource_allocation_and_usage(
        &self,
        log: &ReplicaLogger,
        canister: &mut CanisterState,
        duration_between_blocks: Duration,
    ) -> Result<(), CanisterOutOfCyclesError> {
        let bytes_to_charge = match canister.memory_allocation() {
            // The canister has explicitly asked for a memory allocation, so charge
            // based on it accordingly.
            MemoryAllocation::Reserved(bytes) => bytes,
            // The canister uses best-effort memory allocation, so charge based on current usage.
            MemoryAllocation::BestEffort => canister.memory_usage(self.own_subnet_type),
        };
        if let Err(err) = self.charge_for_memory(
            &mut canister.system_state,
            bytes_to_charge,
            duration_between_blocks,
        ) {
            info!(
                log,
                "Charging canister {} for memory allocation/usage failed with {}",
                canister.canister_id(),
                err
            );
            return Err(err);
        }

        let compute_allocation = canister.compute_allocation();
        if let Err(err) = self.charge_for_compute_allocation(
            &mut canister.system_state,
            compute_allocation,
            duration_between_blocks,
        ) {
            info!(
                log,
                "Charging canister {} for compute allocation failed with {}",
                canister.canister_id(),
                err
            );
            return Err(err);
        }
        Ok(())
    }
/// Charges a canister for its resource allocation and usage for the
/// duration specified. If fees were successfully charged, then returns
/// Ok(CanisterState) else returns Err(CanisterState).
Charges a canister for its resource allocation and usage for the
duration specified. If fees were successfully charged, then returns
Ok(CanisterState) else returns Err(CanisterState).
Charges a canister for its resource allocation and usage for the duration specified . If fees were successfully charged then returns Ok ( CanisterState ) else returns Err ( CanisterState ) .
pub fn charge_canister_for_resource_allocation_and_usage(
        &self,
        log: &ReplicaLogger,
        canister: &mut CanisterState,
        duration_between_blocks: Duration,
    ) -> Result<(), CanisterOutOfCyclesError> {
        let bytes_to_charge = match canister.memory_allocation() {
            // The canister has explicitly asked for a memory allocation, so charge
            // based on it accordingly.
            MemoryAllocation::Reserved(bytes) => bytes,
            // The canister uses best-effort memory allocation, so charge based on current usage.
            MemoryAllocation::BestEffort => canister.memory_usage(self.own_subnet_type),
        };
        if let Err(err) = self.charge_for_memory(
            &mut canister.system_state,
            bytes_to_charge,
            duration_between_blocks,
        ) {
            info!(
                log,
                "Charging canister {} for memory allocation/usage failed with {}",
                canister.canister_id(),
                err
            );
            return Err(err);
        }
        let compute_allocation = canister.compute_allocation();
        if let Err(err) = self.charge_for_compute_allocation(
            &mut canister.system_state,
            compute_allocation,
            duration_between_blocks,
        ) {
            info!(
                log,
                "Charging canister {} for compute allocation failed with {}",
                canister.canister_id(),
                err
            );
            return Err(err);
        }
        Ok(())
    }
pub fn charge_canister_for_resource_allocation_and_usage ( & self , log : & ReplicaLogger , canister : & mut CanisterState , duration_between_blocks : Duration , ) -> Result < ( ) , CanisterOutOfCyclesError > { let bytes_to_charge = match canister . memory_allocation ( ) { // The canister has explicitly asked for a memory allocation, so charge // based on it accordingly. MemoryAllocation :: Reserved ( bytes ) => bytes , // The canister uses best-effort memory allocation, so charge based on current usage. MemoryAllocation :: BestEffort => canister . memory_usage ( self . own_subnet_type ) , } ; if let Err ( err ) = self . charge_for_memory ( & mut canister . system_state , bytes_to_charge , duration_between_blocks , ) { info ! ( log " " canister canister_id ( ) err ) ; return Err ( err ) ; } let compute_allocation = canister . compute_allocation ( ) ; if let Err ( err ) = self . charge_for_compute_allocation ( & mut canister . system_state , compute_allocation , duration_between_blocks , ) { info ! ( log " " canister canister_id ( ) err ) ; return Err ( err ) ; } Ok ( ( ) ) }
Charges a canister for its resource allocation and usage for the
duration specified.
Charges a canister for its resource allocation and usage for the duration specified .
&self
log
&ReplicaLogger
canister
&mut CanisterState
duration_between_blocks
Duration
&self
log
&ReplicaLogger
canister
&mut CanisterState
duration_between_blocks
Duration