Skip to content
Open
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
1,236 changes: 913 additions & 323 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ resolver = "2"
version = "2.0.142"

[workspace.dependencies]
ic-cdk = "0.17.1"
ic-cdk-timers = "0.11.0"
ic-management-canister-types = "0.4.1"
ic-cdk = "0.19.0"
ic-cdk-timers = "1.0.0"
ic-management-canister-types = "0.5.0"

cycles-minting-canister = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
dfn_candid = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
dfn_protobuf = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-crypto-sha2 = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-ledger-core = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-nns-governance = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
ic-sns-swap = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
icp-ledger = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
icrc-ledger-types = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
on_wire = { git = "https://github.com/dfinity/ic", rev = "release-2025-08-14_03-27-base" }
cycles-minting-canister = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
dfn_candid = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
dfn_protobuf = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-base-types = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-crypto-sha2 = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-ledger-core = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-nervous-system-common = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-nns-common = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-nns-constants = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-nns-governance = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
ic-sns-swap = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
icp-ledger = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
icrc-ledger-types = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }
on_wire = { git = "https://github.com/dfinity/ic", rev = "release-2026-04-02_04-48-base" }

[profile.release]
lto = false
Expand Down
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
"IDL2JSON_VERSION": "0.8.8",
"OPTIMIZER_VERSION": "0.3.6",
"BINSTALL_VERSION": "1.3.0",
"DIDC_RELEASE": "2024-05-14",
"DIDC_VERSION": "didc 0.4.0",
"DIDC_RELEASE": "2025-12-18",
"DIDC_VERSION": "didc 0.5.4",
"POCKETIC_VERSION": "3.0.1",
"CARGO_SORT_VERSION": "1.0.9",
"SNSDEMO_RELEASE": "release-2026-04-08",
Expand Down
2 changes: 1 addition & 1 deletion rs/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ on_wire = { workspace = true }

[dev-dependencies]
anyhow = "1.0.95"
candid_parser = "0.1.2"
candid_parser = "0.3.0"
ic_principal = "0.1.0"
maplit = "1.0.2"
pretty_assertions = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion rs/backend/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl CanisterArguments {
#[must_use]
pub fn with_own_canister_id(mut self) -> Self {
self.args
.push(("OWN_CANISTER_ID".to_string(), ic_cdk::api::id().to_string()));
.push(("OWN_CANISTER_ID".to_string(), ic_cdk::api::canister_self().to_string()));
self
}

Expand Down
6 changes: 3 additions & 3 deletions rs/backend/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ fn make_asset_certificate_header(asset_hashes: &AssetHashes, asset_name: &str) -
let mut serializer = serde_cbor::ser::Serializer::new(vec![]);
serializer.self_describe().unwrap();
tree.serialize(&mut serializer)
.unwrap_or_else(|e| ic_cdk::api::trap(&format!("failed to serialize a hash tree: {e}")));
.unwrap_or_else(|e| ic_cdk::api::trap(format!("failed to serialize a hash tree: {e}")));
(
"IC-Certificate".to_string(),
format!(
Expand Down Expand Up @@ -462,7 +462,7 @@ pub fn insert_tar_xz(compressed: Vec<u8>) {
.to_vec();

let name = String::from_utf8(name_bytes.clone()).unwrap_or_else(|e| {
ic_cdk::api::trap(&format!(
ic_cdk::api::trap(format!(
"non-utf8 file name {}: {}",
String::from_utf8_lossy(&name_bytes),
e
Expand Down Expand Up @@ -506,7 +506,7 @@ impl StableState for Assets {

fn update_root_hash(a: &AssetHashes) {
let prefixed_root_hash = &labeled_hash(LABEL_ASSETS, &a.0.root_hash());
ic_cdk::api::set_certified_data(&prefixed_root_hash[..]);
ic_cdk::api::certified_data_set(&prefixed_root_hash[..]);
}

#[test]
Expand Down
15 changes: 7 additions & 8 deletions rs/backend/src/canisters/exchange_rate_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ mod prod {
use ic_nns_constants::EXCHANGE_RATE_CANISTER_ID;

pub async fn get_exchange_rate(request: GetExchangeRateRequest) -> Result<GetExchangeRateResult, String> {
ic_cdk::call::<(GetExchangeRateRequest,), (GetExchangeRateResult,)>(
EXCHANGE_RATE_CANISTER_ID.into(),
"get_exchange_rate",
(request,),
)
.await
.map(|r: (GetExchangeRateResult,)| r.0)
.map_err(|e| e.1)
ic_cdk::call::Call::unbounded_wait(EXCHANGE_RATE_CANISTER_ID.into(), "get_exchange_rate")
.with_arg(request)
.await
.map_err(ic_cdk::call::Error::from)
.and_then(|resp| resp.candid_tuple::<(GetExchangeRateResult,)>().map_err(Into::into))
.map(|r| r.0)
.map_err(|e| format!("{e:?}"))
}
}

Expand Down
11 changes: 8 additions & 3 deletions rs/backend/src/canisters/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ mod prod {
use ic_nns_constants::GOVERNANCE_CANISTER_ID;

pub async fn get_metrics() -> GetMetricsCallResult {
ic_cdk::call(GOVERNANCE_CANISTER_ID.into(), "get_metrics", ())
ic_cdk::call::Call::unbounded_wait(GOVERNANCE_CANISTER_ID.into(), "get_metrics")
.await
.map(|r: (Result<GovernanceCachedMetrics, GovernanceError>,)| r.0)
.map_err(|e| e.1)
.map_err(ic_cdk::call::Error::from)
.and_then(|resp| {
resp.candid_tuple::<(Result<GovernanceCachedMetrics, GovernanceError>,)>()
.map_err(Into::into)
})
.map(|r| r.0)
.map_err(|e| format!("{e:?}"))
}
}

Expand Down
9 changes: 4 additions & 5 deletions rs/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ mod canisters;
mod constants;
mod metrics_encoder;
mod perf;
mod spawn;
mod state;
mod stats;
mod time;
Expand Down Expand Up @@ -95,7 +94,7 @@ pub fn http_request(req: assets::HttpRequest) -> assets::HttpResponse {
}

fn get_caller() -> PrincipalId {
let caller = ic_cdk::api::caller();
let caller = ic_cdk::api::msg_caller();
if caller == candid::Principal::anonymous() {
ic_cdk::api::trap("Anonymous principal is not allowed to call this endpoint.");
}
Expand Down Expand Up @@ -288,7 +287,7 @@ pub fn add_stable_asset(asset_bytes: Vec<u8>) {
insert_asset("/assets/canvaskit/canvaskit.js", Asset::new_stable(asset_bytes));
}
unknown_hash => {
ic_cdk::api::trap(&format!("Unknown asset with hash {unknown_hash}"));
ic_cdk::api::trap(format!("Unknown asset with hash {unknown_hash}"));
}
}
}
Expand All @@ -307,7 +306,7 @@ pub fn add_stable_asset(asset_bytes: Vec<u8>) {
#[must_use]
#[ic_cdk::update]
pub fn create_toy_accounts(num_accounts: u128) -> u64 {
let caller = ic_cdk::caller();
let caller = ic_cdk::api::msg_caller();
if !ic_cdk::api::is_controller(&caller) {
ic_cdk::api::trap("Only the controller may generate toy accounts");
}
Expand All @@ -324,7 +323,7 @@ pub fn create_toy_accounts(num_accounts: u128) -> u64 {
#[must_use]
#[ic_cdk::query]
pub fn get_toy_account(toy_account_index: u64) -> GetAccountResponse {
let caller = ic_cdk::caller();
let caller = ic_cdk::api::msg_caller();
if !ic_cdk::api::is_controller(&caller) {
ic_cdk::api::trap("Only the controller may access toy accounts");
}
Expand Down
2 changes: 1 addition & 1 deletion rs/backend/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl State {
println!("START state::new_restored: ())");
let bytes = with_partitions(Partitions::read_bytes_from_managed_memory);
let state =
State::decode(bytes).unwrap_or_else(|e| trap(&format!("Decoding stable memory failed. Error: {e:?}")));
State::decode(bytes).unwrap_or_else(|e| trap(format!("Decoding stable memory failed. Error: {e:?}")));
println!("END state::new_restored: ()");
state
}
Expand Down
4 changes: 2 additions & 2 deletions rs/backend/src/state/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//!
//! This code also stores virtual memory IDs and other memory functions.
use core::borrow::Borrow;
use ic_cdk::api::stable::WASM_PAGE_SIZE_IN_BYTES;
use ic_cdk::api::trap;
const WASM_PAGE_SIZE_IN_BYTES: u64 = 65536;
use ic_stable_structures::memory_manager::{MemoryId, MemoryManager, VirtualMemory};
use ic_stable_structures::{DefaultMemoryImpl, Memory};
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Partitions {
let len = bytes.len();
let length_field = u64::try_from(len)
.unwrap_or_else(|e| {
trap(&format!(
trap(format!(
"The serialized memory takes more than 2**64 bytes. Amazing: {e:?}"
));
})
Expand Down
2 changes: 1 addition & 1 deletion rs/backend/src/state/partitions/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tests for stable memory layout code.
use super::WASM_PAGE_SIZE_IN_BYTES;
use super::*;
use ic_cdk::api::stable::WASM_PAGE_SIZE_IN_BYTES;
use pretty_assertions::assert_eq;
use std::rc::Rc;

Expand Down
4 changes: 2 additions & 2 deletions rs/backend/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mod tests;
#[cfg(target_arch = "wasm32")]
use core::arch::wasm32::memory_size as wasm_memory_size;
#[cfg(target_arch = "wasm32")]
use ic_cdk::api::stable::stable_size;
use ic_cdk::stable::stable_size;
#[cfg(target_arch = "wasm32")]
use ic_cdk::api::stable::WASM_PAGE_SIZE_IN_BYTES;
const WASM_PAGE_SIZE_IN_BYTES: u64 = 65536;
const GIBIBYTE: u64 = 1 << 30;

/// Returns basic stats for frequent monitoring.
Expand Down
17 changes: 11 additions & 6 deletions rs/backend/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,42 @@ pub mod testing {
use ic_cdk_timers::TimerId;
use slotmap::SlotMap;
use std::cell::RefCell;
use std::future::Future;
use std::pin::Pin;
use std::time::Duration;

pub struct Timer {
pub delay: Duration,
pub func: Box<dyn FnOnce()>,
pub future: Pin<Box<dyn Future<Output = ()>>>,
}

pub struct TimerInterval {
pub interval: Duration,
pub func: Box<dyn FnMut()>,
pub func: Box<dyn FnMut() -> Pin<Box<dyn Future<Output = ()>>>>,
}

thread_local! {
pub static TIMERS: RefCell<SlotMap<TimerId, Timer>> = RefCell::default();
pub static TIMER_INTERVALS: RefCell<SlotMap<TimerId, TimerInterval>> = RefCell::default();
}

pub fn set_timer(delay: Duration, func: impl FnOnce() + 'static) -> TimerId {
pub fn set_timer(delay: Duration, future: impl Future<Output = ()> + 'static) -> TimerId {
TIMERS.with(|timers| {
timers.borrow_mut().insert(Timer {
delay,
func: Box::new(func),
future: Box::pin(future),
})
})
}

pub fn set_timer_interval(interval: Duration, func: impl FnMut() + 'static) -> TimerId {
pub fn set_timer_interval<Fut>(interval: Duration, mut func: impl FnMut() -> Fut + 'static) -> TimerId
where
Fut: Future<Output = ()> + 'static,
{
TIMER_INTERVALS.with(|timer_intervals| {
timer_intervals.borrow_mut().insert(TimerInterval {
interval,
func: Box::new(func),
func: Box::new(move || Box::pin(func()) as Pin<Box<dyn Future<Output = ()>>>),
})
})
}
Expand Down
17 changes: 4 additions & 13 deletions rs/backend/src/tvl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
canisters::{exchange_rate_canister, governance},
constants::{E8S_PER_UNIT, NANOS_PER_UNIT},
spawn,
state::{with_state, with_state_mut},
time,
timer::{set_timer, set_timer_interval},
Expand Down Expand Up @@ -31,25 +30,17 @@ pub fn init_timers() {
}

pub fn start_updating_exchange_rate_in_background() {
set_timer_interval(Duration::from_secs(UPDATE_INTERVAL_SECONDS), || {
spawn::spawn(update_exchange_rate());
});
set_timer_interval(Duration::from_secs(UPDATE_INTERVAL_SECONDS), update_exchange_rate);
// `set_timer_interval` does not run the callback immediately so we also
// call it after 1 second to have an exchange rate available soon.
set_timer(Duration::from_secs(1), || {
spawn::spawn(update_exchange_rate());
});
set_timer(Duration::from_secs(1), update_exchange_rate());
}

fn start_updating_locked_icp_in_the_background() {
set_timer_interval(Duration::from_secs(UPDATE_INTERVAL_SECONDS), || {
spawn::spawn(update_locked_icp_e8s());
});
set_timer_interval(Duration::from_secs(UPDATE_INTERVAL_SECONDS), update_locked_icp_e8s);
// `set_timer_interval` does not run the callback immediately so we also
// call it after 1 second to have an exchange rate available soon.
set_timer(Duration::from_secs(1), || {
spawn::spawn(update_locked_icp_e8s());
});
set_timer(Duration::from_secs(1), update_locked_icp_e8s());
}

/// Converts a number such that it can be interpreted as a fixed-point number
Expand Down
34 changes: 5 additions & 29 deletions rs/backend/src/tvl/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::state::{init_state, with_state, with_state_mut};
use crate::timer;
use crate::tvl::{self, exchange_rate_canister, governance, spawn, time};
use crate::tvl::{self, exchange_rate_canister, governance, time};
use candid::Nat;
use lazy_static::lazy_static;

Expand Down Expand Up @@ -398,13 +398,7 @@ async fn start_updating_exchange_rate_in_background() {
timer.delay,
std::time::Duration::from_secs(expected_timer_delay_seconds)
);
// The timer calls spawn::spawn, which, during the test, adds the future
// to a queue.
(timer.func)();
// Make sure the spawned future is run.
let mut spawned_futures = spawn::testing::drain_spawned_futures();
assert_eq!(spawned_futures.len(), 1);
spawned_futures.pop().unwrap().await;
timer.future.await;
}

// Step 4: Verify the state after calling the 1-time timer.
Expand Down Expand Up @@ -442,13 +436,7 @@ async fn start_updating_exchange_rate_in_background() {
timer.interval,
std::time::Duration::from_secs(expected_timer_interval_seconds)
);
// The timer calls spawn::spawn, which, during the test, adds the future
// to a queue.
(timer.func)();
// Make sure the spawned future is run.
let mut spawned_futures = spawn::testing::drain_spawned_futures();
assert_eq!(spawned_futures.len(), 1);
spawned_futures.pop().unwrap().await;
(timer.func)().await;
}

// Step 4: Verify the state after calling interval timer.
Expand Down Expand Up @@ -505,13 +493,7 @@ async fn start_updating_locked_icp_in_the_background() {
timer.delay,
std::time::Duration::from_secs(expected_timer_delay_seconds)
);
// The timer calls spawn::spawn, which, during the test, adds the future
// to a queue.
(timer.func)();
// Make sure the spawned future is run.
let mut spawned_futures = spawn::testing::drain_spawned_futures();
assert_eq!(spawned_futures.len(), 1);
spawned_futures.pop().unwrap().await;
timer.future.await;
}

// Step 4: Verify the state after calling the 1-time timer.
Expand All @@ -534,13 +516,7 @@ async fn start_updating_locked_icp_in_the_background() {
timer.interval,
std::time::Duration::from_secs(expected_timer_interval_seconds)
);
// The timer calls spawn::spawn, which, during the test, adds the future
// to a queue.
(timer.func)();
// Make sure the spawned future is run.
let mut spawned_futures = spawn::testing::drain_spawned_futures();
assert_eq!(spawned_futures.len(), 1);
spawned_futures.pop().unwrap().await;
(timer.func)().await;
}

// Step 4: Verify the state after calling interval timer.
Expand Down
4 changes: 2 additions & 2 deletions rs/sns_aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ dfn_candid = { workspace = true }
ic-base-types = { workspace = true }
# This next candid is 0.9.0_beta code that fixes serde Nat but has other issues. Keep checking until the issues are fixed.
#candid = { git = "https://github.com/dfinity/candid" , rev = "42ffed660ded37585c4b9f97e3ce90919e24c518" }
ic-cdk = { version = "0.17.1" }
ic-cdk-timers = "0.11.0"
ic-cdk = { version = "0.19.0" }
ic-cdk-timers = "1.0.0"
ic-certified-map = { git = "https://github.com/dfinity/cdk-rs", rev = "58791941b72471e09e3d9e733f2a3d4d54e52b5a" }
ic-management-canister-types = { workspace = true }
ic-nervous-system-common = { workspace = true }
Expand Down
Loading
Loading