From b0a4b7f9987d5820a112cb61b639443bf31a663a Mon Sep 17 00:00:00 2001 From: Francesco Date: Fri, 15 Nov 2024 13:09:31 +0100 Subject: [PATCH] possible overflow --- ic-auction/src/state.rs | 2 +- ic-canister/tests/canister-c/src/lib.rs | 2 +- ic-kit/src/ic.rs | 6 ------ ic-kit/src/mock.rs | 4 ++-- ic-metrics/src/lib.rs | 6 +++--- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/ic-auction/src/state.rs b/ic-auction/src/state.rs index a4ed87e7..e98f32b5 100644 --- a/ic-auction/src/state.rs +++ b/ic-auction/src/state.rs @@ -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. diff --git a/ic-canister/tests/canister-c/src/lib.rs b/ic-canister/tests/canister-c/src/lib.rs index a9ae67a0..e5b771b8 100644 --- a/ic-canister/tests/canister-c/src/lib.rs +++ b/ic-canister/tests/canister-c/src/lib.rs @@ -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); } } diff --git a/ic-kit/src/ic.rs b/ic-kit/src/ic.rs index 06825808..765a882c 100644 --- a/ic-kit/src/ic.rs +++ b/ic-kit/src/ic.rs @@ -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 { diff --git a/ic-kit/src/mock.rs b/ic-kit/src/mock.rs index de495c51..a9b10250 100644 --- a/ic-kit/src/mock.rs +++ b/ic-kit/src/mock.rs @@ -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. diff --git a/ic-metrics/src/lib.rs b/ic-metrics/src/lib.rs index 01049615..c9b5caab 100644 --- a/ic-metrics/src/lib.rs +++ b/ic-metrics/src/lib.rs @@ -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] @@ -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, } @@ -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")] {