// Helper function to create a canister and install the node Wasm bytecode.
Helper function to create a canister and install the node Wasm bytecode.
Helper function to create a canister and install the node Wasm bytecode .
async fn create_and_initialize_node_canister(
        &mut self,
    ) -> Result<(CanisterId, usize, usize), FailedToArchiveBlocks> {
        print("[archive] calling create_canister()");
        let node_canister_id: CanisterId = spawn::create_canister().await;
        let node_block_height_offset: u64 = self
            .nodes_block_ranges
            .last()
            .map(|(_, height_to)| *height_to + 1)
            .unwrap_or(0);
        print("[archive] calling install_code()");
        // We don't inspect the result here because according to MW the install canister
        // code returns an error even after successfully installing the code. We check
        // the existence of the canister immediately afterwards, so it doesn't really
        // matter.
        let _ = spawn::install_code(
            node_canister_id,
            ARCHIVE_NODE_BYTECODE.to_vec(),
            dfn_candid::Candid((
                dfn_core::api::id(),
                node_block_height_offset,
                Some(self.node_max_memory_size_bytes),
            )),
        )
        .await;
        print(format!(
            "[archive] setting controller_id for archive node: {}",
            self.controller_id
        ));
        let res: Result<(), (Option<i32>, String)> = dfn_core::api::call_with_cleanup(
            IC_00,
            &Method::SetController.to_string(),
            dfn_candid::candid_multi_arity,
            (ic_types::ic00::SetControllerArgs::new(
                node_canister_id,
                self.controller_id.into(),
            ),),
        )
        .await;
        res.map_err(|(code, msg)| {
            let s = format!(
                "Setting controller of archive node failed with code {}: {:?}",
                code.unwrap_or_default(),
                msg
            );
            FailedToArchiveBlocks(s)
        })?;
        self.nodes.push(node_canister_id);
        let node_index = self.last_node_index();
        let remaining_capacity: usize = dfn_core::api::call_with_cleanup(
            node_canister_id,
            "remaining_capacity",
            dfn_candid::candid_one,
            (),
        )
        .await
        .map_err(|(_, msg)| FailedToArchiveBlocks(msg))?;
        Ok((node_canister_id, node_index, remaining_capacity))
    }
async fn create_and_initialize_node_canister ( & mut self , ) -> Result < ( CanisterId , usize , usize ) , FailedToArchiveBlocks > { print ( " " ) ; let node_canister_id : CanisterId = spawn :: create_canister ( ) . await ; let node_block_height_offset : u64 = self . nodes_block_ranges . last ( ) . map ( | ( _ , height_to ) | * height_to + 1 ) . unwrap_or ( 0 ) ; print ( " " ) ; // We don't inspect the result here because according to MW the install canister // code returns an error even after successfully installing the code. We check // the existence of the canister immediately afterwards, so it doesn't really // matter. let _ = spawn :: install_code ( node_canister_id , ARCHIVE_NODE_BYTECODE . to_vec ( ) , dfn_candid :: Candid ( ( dfn_core :: api :: id ( ) , node_block_height_offset , Some ( self . node_max_memory_size_bytes ) , ) ) , ) . await ; print ( format ! ( " " self controller_id ) ) ; let res : Result < ( ) , ( Option < i32 > , String ) > = dfn_core :: api :: call_with_cleanup ( IC_00 , & Method :: SetController . to_string ( ) , dfn_candid :: candid_multi_arity , ( ic_types :: ic00 :: SetControllerArgs :: new ( node_canister_id , self . controller_id . into ( ) , ) , ) , ) . await ; res . map_err ( | ( code , msg ) | { let s = format ! ( " " code unwrap_or_default ( ) msg ) ; FailedToArchiveBlocks ( s ) } ) ? ; self . nodes . push ( node_canister_id ) ; let node_index = self . last_node_index ( ) ; let remaining_capacity : usize = dfn_core :: api :: call_with_cleanup ( node_canister_id , " " , dfn_candid :: candid_one , ( ) , ) . await . map_err ( | ( _ , msg ) | FailedToArchiveBlocks ( msg ) ) ? ; Ok ( ( node_canister_id , node_index , remaining_capacity ) ) }
Helper function to create a canister and install the node Wasm bytecode.
Helper function to create a canister and install the node Wasm bytecode .
&mut self