Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove possible overflow #235

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ic-auction/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl AuctionState {

fn get_fee_ratio(&self) -> f64 {
let min_cycles = self.min_cycles as f64;
let current_cycles = ic::balance() as f64;
let current_cycles = ic::balance128() as f64;
if min_cycles == 0.0 {
// Setting min_cycles to zero effectively turns off the auction functionality, as all the
// fees will go to the owner.
Expand Down
2 changes: 1 addition & 1 deletion ic-canister/tests/canister-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod tests {

let metrics_snapshot = metrics.map.into_iter().next().unwrap().1;

assert_eq!(metrics_snapshot.cycles, 1e+14 as u64);
assert_eq!(metrics_snapshot.cycles, 1e+14 as u128);
assert_eq!(metrics_snapshot.stable_memory_size, 0);
}
}
6 changes: 0 additions & 6 deletions ic-kit/src/ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ pub fn time() -> u64 {
get_context().time()
}

/// The balance of the canister.
#[inline(always)]
pub fn balance() -> u64 {
get_context().balance()
}

/// The balance of the canister.
#[inline(always)]
pub fn balance128() -> u128 {
Expand Down
4 changes: 2 additions & 2 deletions ic-kit/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ mod tests {
}

/// An update method that returns the balance of the canister.
pub fn balance() -> u64 {
ic::balance()
pub fn balance() -> u128 {
ic::balance128()
}

/// An update method that returns the number of cycles provided by the user in the call.
Expand Down
6 changes: 3 additions & 3 deletions ic-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! #[update]
//! fn collect_metrics(&mut self) {
//! let mut metrics = self.metrics.borrow_mut();
//! metrics.insert(Metrics { cycles: ic_kit::ic::balance() });
//! metrics.insert(Metrics { cycles: ic_kit::ic::balance128() });
//! }
//!
//! #[query]
Expand Down Expand Up @@ -70,7 +70,7 @@ pub struct MetricsStorage {

#[derive(CandidType, Deserialize, IcStorage, Default, Clone, Debug, PartialEq, Eq)]
pub struct MetricsData {
pub cycles: u64,
pub cycles: u128,
pub stable_memory_size: u64,
pub heap_memory_size: u64,
}
Expand Down Expand Up @@ -129,7 +129,7 @@ pub trait Metrics: Canister {

fn curr_values() -> MetricsData {
MetricsData {
cycles: ic_exports::ic_kit::ic::balance(),
cycles: ic_exports::ic_kit::ic::balance128(),
stable_memory_size: {
#[cfg(target_family = "wasm")]
{
Expand Down