// Enqueues an ingress message into input queues.
Enqueues an ingress message into input queues.
Enqueues an ingress message into input queues .
fn enqueue(
        &self,
        state: &mut ReplicatedState,
        msg: SignedIngressContent,
    ) -> Result<(), StateError> {
        // Compute the cost of induction.
        let induction_cost = match self.cycles_account_manager.ingress_induction_cost(&msg) {
            Ok(induction_cost) => induction_cost,
            Err(IngressInductionCostError::UnknownSubnetMethod) => {
                return Err(StateError::UnknownSubnetMethod(
                    msg.method_name().to_string(),
                ))
            }
            Err(IngressInductionCostError::InvalidSubnetPayload) => {
                return Err(StateError::InvalidSubnetPayload)
            }
        };
        match induction_cost {
            IngressInductionCost::Free => {
                // Only subnet methods can be free. These are enqueued directly.
                assert!(is_subnet_message(&msg, self.own_subnet_id));
                state.push_ingress(msg)
            }
            IngressInductionCost::Fee { payer, cost } => {
                // Get the paying canister from the state.
                let canister = match state.canister_states.get_mut(&payer) {
                    Some(canister) => canister,
                    None => return Err(StateError::CanisterNotFound(payer)),
                };
                // Ensure the canister is running if the message isn't to a subnet.
                if !is_subnet_message(&msg, self.own_subnet_id) {
                    match canister.status() {
                        CanisterStatusType::Running => {}
                        CanisterStatusType::Stopping => {
                            return Err(StateError::CanisterStopping(canister.canister_id()))
                        }
                        CanisterStatusType::Stopped => {
                            return Err(StateError::CanisterStopped(canister.canister_id()))
                        }
                    }
                }
                // Withdraw cost of inducting the message.
                let memory_usage = canister.memory_usage(state.metadata.own_subnet_type);
                let compute_allocation = canister.scheduler_state.compute_allocation;
                if let Err(err) = self.cycles_account_manager.consume_cycles(
                    &mut canister.system_state,
                    memory_usage,
                    compute_allocation,
                    cost,
                ) {
                    return Err(StateError::CanisterOutOfCycles(err));
                }
                state.push_ingress(msg)
            }
        }
    }
fn enqueue ( & self , state : & mut ReplicatedState , msg : SignedIngressContent , ) -> Result < ( ) , StateError > { // Compute the cost of induction. let induction_cost = match self . cycles_account_manager . ingress_induction_cost ( & msg ) { Ok ( induction_cost ) => induction_cost , Err ( IngressInductionCostError :: UnknownSubnetMethod ) => { return Err ( StateError :: UnknownSubnetMethod ( msg . method_name ( ) . to_string ( ) , ) ) } Err ( IngressInductionCostError :: InvalidSubnetPayload ) => { return Err ( StateError :: InvalidSubnetPayload ) } } ; match induction_cost { IngressInductionCost :: Free => { // Only subnet methods can be free. These are enqueued directly. assert ! ( is_subnet_message ( msg self own_subnet_id ) ) ; state . push_ingress ( msg ) } IngressInductionCost :: Fee { payer , cost } => { // Get the paying canister from the state. let canister = match state . canister_states . get_mut ( & payer ) { Some ( canister ) => canister , None => return Err ( StateError :: CanisterNotFound ( payer ) ) , } ; // Ensure the canister is running if the message isn't to a subnet. if ! is_subnet_message ( & msg , self . own_subnet_id ) { match canister . status ( ) { CanisterStatusType :: Running => { } CanisterStatusType :: Stopping => { return Err ( StateError :: CanisterStopping ( canister . canister_id ( ) ) ) } CanisterStatusType :: Stopped => { return Err ( StateError :: CanisterStopped ( canister . canister_id ( ) ) ) } } } // Withdraw cost of inducting the message. let memory_usage = canister . memory_usage ( state . metadata . own_subnet_type ) ; let compute_allocation = canister . scheduler_state . compute_allocation ; if let Err ( err ) = self . cycles_account_manager . consume_cycles ( & mut canister . system_state , memory_usage , compute_allocation , cost , ) { return Err ( StateError :: CanisterOutOfCycles ( err ) ) ; } state . push_ingress ( msg ) } } }
Enqueues an ingress message into input queues.
Enqueues an ingress message into input queues .
&self
state
&mut ReplicatedState
msg
SignedIngressContent