async fn node_and_capacity(
        &mut self,
        needed: usize,
    ) -> Result<(CanisterId, usize, usize), FailedToArchiveBlocks> {
        let last_node_canister_id: Option<CanisterId> = self.nodes.last().copied();
        match last_node_canister_id {
            // Not a single archive node exists. Create one.
            None => {
                print("[archive] creating the first archive node");
                let (node_canister_id, node_index, remaining_capacity) =
                    self.create_and_initialize_node_canister().await?;
                print(format!(
                    "[archive] node canister id: {}, index: {}",
                    node_canister_id, node_index
                ));

                Ok((node_canister_id, node_index, remaining_capacity))
            }
            // Some archive node exists. Use it, or, if already full, create a
            // new node.
            Some(last_node_canister_id) => {
                let remaining_capacity: usize = dfn_core::api::call_with_cleanup(
                    last_node_canister_id,
                    "remaining_capacity",
                    dfn_candid::candid,
                    (),
                )
                .await
                .map_err(|(_, msg)| FailedToArchiveBlocks(msg))?;
                if remaining_capacity < needed {
                    print("[archive] last node is full. creating a new archive node");
                    let (node_canister_id, node_index, remaining_capacity) =
                        self.create_and_initialize_node_canister().await?;
                    print(format!(
                        "[archive] node canister id: {}, index: {}",
                        node_canister_id, node_index
                    ));
                    Ok((node_canister_id, node_index, remaining_capacity))
                } else {
                    let node_index = self.last_node_index();
                    print(format!(
                        "[archive] reusing existing last node {} with index {} and capacity {}",
                        last_node_canister_id, node_index, remaining_capacity
                    ));
                    Ok((last_node_canister_id, node_index, remaining_capacity))
                }
            }
        }
    }
/// Helper function to find the CanisterId of the node that can accept
/// blocks, or create one, and find how many blocks can be accepted.
Helper function to find the CanisterId of the node that can accept
blocks, or create one, and find how many blocks can be accepted.
Helper function to find the CanisterId of the node that can accept blocks or create one and find how many blocks can be accepted .
async fn node_and_capacity(
        &mut self,
        needed: usize,
    ) -> Result<(CanisterId, usize, usize), FailedToArchiveBlocks> {
        let last_node_canister_id: Option<CanisterId> = self.nodes.last().copied();
        match last_node_canister_id {
            // Not a single archive node exists. Create one.
            None => {
                print("[archive] creating the first archive node");
                let (node_canister_id, node_index, remaining_capacity) =
                    self.create_and_initialize_node_canister().await?;
                print(format!(
                    "[archive] node canister id: {}, index: {}",
                    node_canister_id, node_index
                ));
                Ok((node_canister_id, node_index, remaining_capacity))
            }
            // Some archive node exists. Use it, or, if already full, create a
            // new node.
            Some(last_node_canister_id) => {
                let remaining_capacity: usize = dfn_core::api::call_with_cleanup(
                    last_node_canister_id,
                    "remaining_capacity",
                    dfn_candid::candid,
                    (),
                )
                .await
                .map_err(|(_, msg)| FailedToArchiveBlocks(msg))?;
                if remaining_capacity < needed {
                    print("[archive] last node is full. creating a new archive node");
                    let (node_canister_id, node_index, remaining_capacity) =
                        self.create_and_initialize_node_canister().await?;
                    print(format!(
                        "[archive] node canister id: {}, index: {}",
                        node_canister_id, node_index
                    ));
                    Ok((node_canister_id, node_index, remaining_capacity))
                } else {
                    let node_index = self.last_node_index();
                    print(format!(
                        "[archive] reusing existing last node {} with index {} and capacity {}",
                        last_node_canister_id, node_index, remaining_capacity
                    ));
                    Ok((last_node_canister_id, node_index, remaining_capacity))
                }
            }
        }
    }
async fn node_and_capacity ( & mut self , needed : usize , ) -> Result < ( CanisterId , usize , usize ) , FailedToArchiveBlocks > { let last_node_canister_id : Option < CanisterId > = self . nodes . last ( ) . copied ( ) ; match last_node_canister_id { // Not a single archive node exists. Create one. None => { print ( " " ) ; let ( node_canister_id , node_index , remaining_capacity ) = self . create_and_initialize_node_canister ( ) . await ? ; print ( format ! ( " " node_canister_id node_index ) ) ; Ok ( ( node_canister_id , node_index , remaining_capacity ) ) } // Some archive node exists. Use it, or, if already full, create a // new node. Some ( last_node_canister_id ) => { let remaining_capacity : usize = dfn_core :: api :: call_with_cleanup ( last_node_canister_id , " " , dfn_candid :: candid , ( ) , ) . await . map_err ( | ( _ , msg ) | FailedToArchiveBlocks ( msg ) ) ? ; if remaining_capacity < needed { print ( " " ) ; let ( node_canister_id , node_index , remaining_capacity ) = self . create_and_initialize_node_canister ( ) . await ? ; print ( format ! ( " " node_canister_id node_index ) ) ; Ok ( ( node_canister_id , node_index , remaining_capacity ) ) } else { let node_index = self . last_node_index ( ) ; print ( format ! ( " " last_node_canister_id node_index remaining_capacity ) ) ; Ok ( ( last_node_canister_id , node_index , remaining_capacity ) ) } } } }
Helper function to find the CanisterId of the node that can accept
blocks, or create one, and find how many blocks can be accepted.
Helper function to find the CanisterId of the node that can accept blocks or create one and find how many blocks can be accepted .
&mut self
needed
usize
&mut self
needed
usize