Skip to content

Commit

Permalink
updated cycle cost required for upgrading canister
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-sawlani-yral committed Nov 22, 2024
1 parent 13fa185 commit 5fdce76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use shared_utils::{
},
};

use crate::{util::canister_management, CANISTER_DATA};
use crate::{
util::canister_management::{self, recharge_canister_for_installing_wasm},
CANISTER_DATA,
};

// * dfx canister call user_index upgrade_specific_individual_user_canister_with_latest_wasm '(principal "", principal "", null)' --network ic

Expand All @@ -20,7 +23,7 @@ async fn upgrade_specific_individual_user_canister_with_latest_wasm(
user_canister_id: Principal,
user_principal_id: Option<Principal>,
upgrade_mode: Option<CanisterInstallMode>,
) -> String {
) -> Result<(), String> {
let known_principal_ids = CANISTER_DATA.with(|canister_data_ref_cell| {
canister_data_ref_cell
.borrow()
Expand All @@ -46,6 +49,8 @@ async fn upgrade_specific_individual_user_canister_with_latest_wasm(
.unwrap()
});

recharge_canister_for_installing_wasm(user_canister_id).await?;

match canister_management::upgrade_individual_user_canister(
user_canister_id,
upgrade_mode.unwrap_or(CanisterInstallMode::Upgrade(None)),
Expand All @@ -60,7 +65,7 @@ async fn upgrade_specific_individual_user_canister_with_latest_wasm(
)
.await
{
Ok(_) => "Success".to_string(),
Err(e) => e.1,
Ok(_) => Ok(()),
Err(e) => Err(e.1),
}
}
4 changes: 3 additions & 1 deletion src/lib/shared_utils/src/cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ pub fn calculate_required_cycles_for_upgrading(
+ ((RESERVED_NUMBER_OF_INSTRUCTIONS_FOR_INSTALL_CODE
* COST_PER_BILLION_INSTRUCTION_EXECUTED)
/ 1_000_000_000);
freezing_threshold_cycles + cycles_required_for_upgrade_execution

//100B cycles to safeguard the upgrade process
freezing_threshold_cycles + cycles_required_for_upgrade_execution + 100_000_000_000
}

#[cfg(test)]
Expand Down

0 comments on commit 5fdce76

Please sign in to comment.