// A helper function that enqueues any outgoing requests that the canister
// has.
A helper function that enqueues any outgoing requests that the canister
has.
A helper function that enqueues any outgoing requests that the canister has .
fn enqueue_requests(&mut self, canister: &mut CanisterState) -> EnqueueRequestsResult {
        let mut sent_messages = false;
        let canister_id = canister.canister_id();
        let outgoing_messages: Vec<_> =
            canister.output_into_iter().map(|(_, _, msg)| msg).collect();
        let call_context_manager = canister
            .system_state
            .call_context_manager_mut()
            .unwrap_or_else(|| {
                fatal!(
                    self.log,
                    "Canister {}: Expected to find a CallContextmanager",
                    canister_id
                )
            });
        // When we deserialize the canister state from the replicated state, it
        // is possible that it already had some messages in its output queues.
        // As we iterate over the messages below, we only want to handle
        // messages that were produced by this module.
        for msg in outgoing_messages {
            match msg {
                RequestOrResponse::Request(msg) => {
                    // Responses here are only those triggered by the Request that we sent,
                    // so we are sure the unwrap here is safe.
                    let call_origin = call_context_manager
                        .call_origin(
                            call_context_manager
                                .peek_callback(msg.sender_reply_callback)
                                .unwrap()
                                .call_context_id,
                        )
                        .unwrap();
                    match call_origin {
                        // Messages of these types are not produced by this
                        // module so must have existed on the canister's output
                        // queue from before.
                        CallOrigin::CanisterUpdate(_, _)
                        | CallOrigin::Heartbeat
                        | CallOrigin::Ingress(_, _) => continue,
                        // We never serialize messages of such types in the
                        // canister's state so these must have been produced by
                        // this module.
                        CallOrigin::Query(_) | CallOrigin::CanisterQuery(_, _) => {}
                    }
                    if msg.receiver == canister_id || self.canisters.contains_key(&msg.receiver) {
                        // Call graph loop detector. There is already a canister
                        // in the call graph that is waiting for some responses
                        // to come back and this canister is trying to send it
                        // messages. The MVP inter-canister queries
                        // implementation does not support loops.
                        return EnqueueRequestsResult::LoopDetected;
                    }
                    sent_messages = true;
                    self.outstanding_requests.push(msg);
                }
                // Messages of these types are not produced by this
                // module so must have existed on the canister's output
                // queue from before.
                RequestOrResponse::Response(_) => {}
            }
        }
        if sent_messages {
            EnqueueRequestsResult::MessagesEnqueued
        } else {
            EnqueueRequestsResult::NoMessages
        }
    }
fn enqueue_requests ( & mut self , canister : & mut CanisterState ) -> EnqueueRequestsResult { let mut sent_messages = false ; let canister_id = canister . canister_id ( ) ; let outgoing_messages : Vec < _ > = canister . output_into_iter ( ) . map ( | ( _ , _ , msg ) | msg ) . collect ( ) ; let call_context_manager = canister . system_state . call_context_manager_mut ( ) . unwrap_or_else ( | | { fatal ! ( self log " " canister_id ) } ) ; // When we deserialize the canister state from the replicated state, it // is possible that it already had some messages in its output queues. // As we iterate over the messages below, we only want to handle // messages that were produced by this module. for msg in outgoing_messages { match msg { RequestOrResponse :: Request ( msg ) => { // Responses here are only those triggered by the Request that we sent, // so we are sure the unwrap here is safe. let call_origin = call_context_manager . call_origin ( call_context_manager . peek_callback ( msg . sender_reply_callback ) . unwrap ( ) . call_context_id , ) . unwrap ( ) ; match call_origin { // Messages of these types are not produced by this // module so must have existed on the canister's output // queue from before. CallOrigin :: CanisterUpdate ( _ , _ ) | CallOrigin :: Heartbeat | CallOrigin :: Ingress ( _ , _ ) => continue , // We never serialize messages of such types in the // canister's state so these must have been produced by // this module. CallOrigin :: Query ( _ ) | CallOrigin :: CanisterQuery ( _ , _ ) => { } } if msg . receiver == canister_id || self . canisters . contains_key ( & msg . receiver ) { // Call graph loop detector. There is already a canister // in the call graph that is waiting for some responses // to come back and this canister is trying to send it // messages. The MVP inter-canister queries // implementation does not support loops. return EnqueueRequestsResult :: LoopDetected ; } sent_messages = true ; self . outstanding_requests . push ( msg ) ; } // Messages of these types are not produced by this // module so must have existed on the canister's output // queue from before. RequestOrResponse :: Response ( _ ) => { } } } if sent_messages { EnqueueRequestsResult :: MessagesEnqueued } else { EnqueueRequestsResult :: NoMessages } }
A helper function that enqueues any outgoing requests that the canister
has.
A helper function that enqueues any outgoing requests that the canister has .
&mut self
canister
&mut CanisterState