fn charge_canisters_for_resource_allocation_and_usage(
        &self,
        state: &mut ReplicatedState,
        time_of_previous_batch: Time,
    ) {
        let timer = self
            .metrics
            .charge_resource_allocation_and_use_duration
            .start_timer();
        let duration_between_blocks = state
            .metadata
            .duration_between_batches(time_of_previous_batch);

        let canisters = state.take_canister_states();
        let mut canisters_to_keep = BTreeMap::new();

        for (_, canister) in canisters.into_iter() {
            match self
                .cycles_account_manager
                .charge_canister_for_resource_allocation_and_usage(
                    &self.log,
                    canister,
                    duration_between_blocks,
                ) {
                Ok(canister) => {
                    canisters_to_keep.insert(canister.canister_id(), canister);
                }
                Err(mut canister) => {
                    info!(
                        self.log,
                        "Uninstalling canister {} because it ran out of cycles",
                        canister.canister_id()
                    );
                    self.metrics.num_canisters_uninstalled_out_of_cycles.inc();
                    let rejects =
                        uninstall_canister(&self.log, &mut canister, state.path(), state.time());
                    process_responses(rejects, state, Arc::clone(&self.ingress_history_writer));
                    canister.scheduler_state.compute_allocation = ComputeAllocation::zero();
                    canister.system_state.memory_allocation = None;
                }
            }
        }

        state.put_canister_states(canisters_to_keep);
        drop(timer);
    }
// 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,
        time_of_previous_batch: Time,
    ) {
        let timer = self
            .metrics
            .charge_resource_allocation_and_use_duration
            .start_timer();
        let duration_between_blocks = state
            .metadata
            .duration_between_batches(time_of_previous_batch);
        let canisters = state.take_canister_states();
        let mut canisters_to_keep = BTreeMap::new();
        for (_, canister) in canisters.into_iter() {
            match self
                .cycles_account_manager
                .charge_canister_for_resource_allocation_and_usage(
                    &self.log,
                    canister,
                    duration_between_blocks,
                ) {
                Ok(canister) => {
                    canisters_to_keep.insert(canister.canister_id(), canister);
                }
                Err(mut canister) => {
                    info!(
                        self.log,
                        "Uninstalling canister {} because it ran out of cycles",
                        canister.canister_id()
                    );
                    self.metrics.num_canisters_uninstalled_out_of_cycles.inc();
                    let rejects =
                        uninstall_canister(&self.log, &mut canister, state.path(), state.time());
                    process_responses(rejects, state, Arc::clone(&self.ingress_history_writer));
                    canister.scheduler_state.compute_allocation = ComputeAllocation::zero();
                    canister.system_state.memory_allocation = None;
                }
            }
        }
        state.put_canister_states(canisters_to_keep);
        drop(timer);
    }
fn charge_canisters_for_resource_allocation_and_usage ( & self , state : & mut ReplicatedState , time_of_previous_batch : Time , ) { let timer = self . metrics . charge_resource_allocation_and_use_duration . start_timer ( ) ; let duration_between_blocks = state . metadata . duration_between_batches ( time_of_previous_batch ) ; let canisters = state . take_canister_states ( ) ; let mut canisters_to_keep = BTreeMap :: new ( ) ; for ( _ , canister ) in canisters . into_iter ( ) { match self . cycles_account_manager . charge_canister_for_resource_allocation_and_usage ( & self . log , canister , duration_between_blocks , ) { Ok ( canister ) => { canisters_to_keep . insert ( canister . canister_id ( ) , canister ) ; } Err ( mut canister ) => { info ! ( self log " " canister canister_id ( ) ) ; self . metrics . num_canisters_uninstalled_out_of_cycles . inc ( ) ; let rejects = uninstall_canister ( & self . log , & mut canister , state . path ( ) , state . time ( ) ) ; process_responses ( rejects , state , Arc :: clone ( & self . ingress_history_writer ) ) ; canister . scheduler_state . compute_allocation = ComputeAllocation :: zero ( ) ; canister . system_state . memory_allocation = None ; } } } state . put_canister_states ( canisters_to_keep ) ; drop ( timer ) ; }
Charge canisters for their resource allocation and usage.
Charge canisters for their resource allocation and usage .
&self
state
&mut ReplicatedState
time_of_previous_batch
Time
&self
state
&mut ReplicatedState
time_of_previous_batch
Time