fn charge_canisters_for_resource_allocation_and_usage(&self, state: &mut ReplicatedState) {
        let duration_since_last_charge = state
            .metadata
            .duration_between_batches(state.metadata.time_of_last_allocation_charge);

        if state.time()
            < state.metadata.time_of_last_allocation_charge
                + self
                    .cycles_account_manager
                    .duration_between_allocation_charges()
        {
            return;
        } else {
            state.metadata.time_of_last_allocation_charge = state.time();
        }

        let state_path = state.root.clone();
        let state_time = state.time();
        let mut all_rejects = Vec::new();
        for canister in state.canisters_iter_mut() {
            if self
                .cycles_account_manager
                .charge_canister_for_resource_allocation_and_usage(
                    &self.log,
                    canister,
                    duration_since_last_charge,
                )
                .is_err()
            {
                all_rejects.push(uninstall_canister(
                    &self.log,
                    canister,
                    &state_path,
                    state_time,
                ));
                canister.scheduler_state.compute_allocation = ComputeAllocation::zero();
                canister.system_state.memory_allocation = MemoryAllocation::BestEffort;

                info!(
                    self.log,
                    "Uninstalling canister {} because it ran out of cycles",
                    canister.canister_id()
                );
                self.metrics.num_canisters_uninstalled_out_of_cycles.inc();
            }
        }

        // Send rejects to any requests that were forcibly closed while uninstalling.
        for rejects in all_rejects.into_iter() {
            process_responses(
                rejects,
                state,
                Arc::clone(&self.ingress_history_writer),
                self.log.clone(),
            );
        }
    }
// Charge canisters for their resource allocation and usage. Canisters
// that did not manage to pay are uninstalled.
Charge canisters for their resource allocation and usage. Canisters
that did not manage to pay are uninstalled.
Charge canisters for their resource allocation and usage . Canisters that did not manage to pay are uninstalled .
fn charge_canisters_for_resource_allocation_and_usage(&self, state: &mut ReplicatedState) {
        let duration_since_last_charge = state
            .metadata
            .duration_between_batches(state.metadata.time_of_last_allocation_charge);
        if state.time()
            < state.metadata.time_of_last_allocation_charge
                + self
                    .cycles_account_manager
                    .duration_between_allocation_charges()
        {
            return;
        } else {
            state.metadata.time_of_last_allocation_charge = state.time();
        }
        let state_path = state.root.clone();
        let state_time = state.time();
        let mut all_rejects = Vec::new();
        for canister in state.canisters_iter_mut() {
            if self
                .cycles_account_manager
                .charge_canister_for_resource_allocation_and_usage(
                    &self.log,
                    canister,
                    duration_since_last_charge,
                )
                .is_err()
            {
                all_rejects.push(uninstall_canister(
                    &self.log,
                    canister,
                    &state_path,
                    state_time,
                ));
                canister.scheduler_state.compute_allocation = ComputeAllocation::zero();
                canister.system_state.memory_allocation = MemoryAllocation::BestEffort;
                info!(
                    self.log,
                    "Uninstalling canister {} because it ran out of cycles",
                    canister.canister_id()
                );
                self.metrics.num_canisters_uninstalled_out_of_cycles.inc();
            }
        }
        // Send rejects to any requests that were forcibly closed while uninstalling.
        for rejects in all_rejects.into_iter() {
            process_responses(
                rejects,
                state,
                Arc::clone(&self.ingress_history_writer),
                self.log.clone(),
            );
        }
    }
fn charge_canisters_for_resource_allocation_and_usage ( & self , state : & mut ReplicatedState ) { let duration_since_last_charge = state . metadata . duration_between_batches ( state . metadata . time_of_last_allocation_charge ) ; if state . time ( ) < state . metadata . time_of_last_allocation_charge + self . cycles_account_manager . duration_between_allocation_charges ( ) { return ; } else { state . metadata . time_of_last_allocation_charge = state . time ( ) ; } let state_path = state . root . clone ( ) ; let state_time = state . time ( ) ; let mut all_rejects = Vec :: new ( ) ; for canister in state . canisters_iter_mut ( ) { if self . cycles_account_manager . charge_canister_for_resource_allocation_and_usage ( & self . log , canister , duration_since_last_charge , ) . is_err ( ) { all_rejects . push ( uninstall_canister ( & self . log , canister , & state_path , state_time , ) ) ; canister . scheduler_state . compute_allocation = ComputeAllocation :: zero ( ) ; canister . system_state . memory_allocation = MemoryAllocation :: BestEffort ; info ! ( self log " " canister canister_id ( ) ) ; self . metrics . num_canisters_uninstalled_out_of_cycles . inc ( ) ; } } // Send rejects to any requests that were forcibly closed while uninstalling. for rejects in all_rejects . into_iter ( ) { process_responses ( rejects , state , Arc :: clone ( & self . ingress_history_writer ) , self . log . clone ( ) , ) ; } }
Charge canisters for their resource allocation and usage.
Charge canisters for their resource allocation and usage .
&self
state
&mut ReplicatedState
&self
state
&mut ReplicatedState