diff --git a/rs/ledger_suite/common/ledger_canister_core/src/runtime.rs b/rs/ledger_suite/common/ledger_canister_core/src/runtime.rs index f53904667b67..8f5a25a7731e 100644 --- a/rs/ledger_suite/common/ledger_canister_core/src/runtime.rs +++ b/rs/ledger_suite/common/ledger_canister_core/src/runtime.rs @@ -1,4 +1,3 @@ -#![allow(deprecated)] use async_trait::async_trait; use candid::utils::{ArgumentDecoder, ArgumentEncoder}; use ic_base_types::{CanisterId, PrincipalId}; @@ -41,11 +40,11 @@ pub struct CdkRuntime; #[async_trait] impl Runtime for CdkRuntime { fn id() -> CanisterId { - CanisterId::unchecked_from_principal(PrincipalId::from(ic_cdk::api::id())) + CanisterId::unchecked_from_principal(PrincipalId::from(ic_cdk::api::canister_self())) } fn print(msg: impl AsRef) { - ic_cdk::api::print(msg) + ic_cdk::api::debug_print(msg) } async fn call( @@ -59,8 +58,34 @@ impl Runtime for CdkRuntime { Out: for<'a> ArgumentDecoder<'a>, { let principal_id = PrincipalId::from(id); - ic_cdk::api::call::call_with_payment(principal_id.into(), method, args, cycles) + // We use `-1` as a sentinel for failures that do not have an associated + // IC reject code (insufficient cycles, `ic0.call_perform` failure, + // candid decoding errors). The positive range matches + // `ic_error_types::RejectCode` so callers can reliably distinguish the + // two. This mirrors the convention in + // `rs/nervous_system/clients/src/exchange_rate_canister_client.rs`. + const SENTINEL_CALL_FAILURE: i32 = -1; + let response = ic_cdk::call::Call::unbounded_wait(principal_id.into(), method) + .with_args(&args) + .with_cycles(cycles as u128) .await - .map_err(|(code, msg)| (code as i32, msg)) + .map_err(|err| match err { + ic_cdk::call::CallFailed::CallRejected(rejected) => ( + rejected + .reject_code() + .map(|code| code as i32) + .unwrap_or(SENTINEL_CALL_FAILURE), + rejected.reject_message().to_string(), + ), + ic_cdk::call::CallFailed::InsufficientLiquidCycleBalance(e) => { + (SENTINEL_CALL_FAILURE, e.to_string()) + } + ic_cdk::call::CallFailed::CallPerformFailed(e) => { + (SENTINEL_CALL_FAILURE, e.to_string()) + } + })?; + response + .candid_tuple::() + .map_err(|err| (SENTINEL_CALL_FAILURE, err.to_string())) } } diff --git a/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u256.yml b/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u256.yml index 9996b29af8a8..e5317cbf1a2f 100644 --- a/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u256.yml +++ b/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u256.yml @@ -2,7 +2,7 @@ benches: bench_icrc1_transfers: total: calls: 1 - instructions: 54503709185 + instructions: 54515026271 heap_increase: 264 stable_memory_increase: 256 scopes: @@ -13,59 +13,59 @@ benches: stable_memory_increase: 0 icrc1_transfer: calls: 1 - instructions: 12932131566 + instructions: 12932331392 heap_increase: 32 stable_memory_increase: 0 icrc2_approve: calls: 1 - instructions: 19387929174 + instructions: 19388798999 heap_increase: 29 stable_memory_increase: 128 icrc2_transfer_from: calls: 1 - instructions: 21482922683 + instructions: 21483112508 heap_increase: 3 stable_memory_increase: 0 icrc3_get_blocks: calls: 1 - instructions: 8714812 + instructions: 8712614 heap_increase: 0 stable_memory_increase: 0 post_upgrade: calls: 1 - instructions: 342353779 + instructions: 351358365 heap_increase: 71 stable_memory_increase: 0 pre_upgrade: calls: 1 - instructions: 148924963 + instructions: 149978485 heap_increase: 129 stable_memory_increase: 128 upgrade: calls: 1 - instructions: 491281484 + instructions: 501339592 heap_increase: 200 stable_memory_increase: 128 bench_upgrade_baseline: total: calls: 1 - instructions: 8690537 + instructions: 8695232 heap_increase: 258 stable_memory_increase: 128 scopes: post_upgrade: calls: 1 - instructions: 8609155 + instructions: 8613828 heap_increase: 129 stable_memory_increase: 0 pre_upgrade: calls: 1 - instructions: 78458 + instructions: 78480 heap_increase: 129 stable_memory_increase: 128 upgrade: calls: 1 - instructions: 8689629 + instructions: 8694324 heap_increase: 258 stable_memory_increase: 128 version: 0.4.1 diff --git a/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u64.yml b/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u64.yml index 0db46f8c3142..b4bdf562373f 100644 --- a/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u64.yml +++ b/rs/ledger_suite/icrc1/ledger/canbench_results/canbench_u64.yml @@ -2,28 +2,28 @@ benches: bench_icrc1_transfers: total: calls: 1 - instructions: 52125398932 + instructions: 52115351782 heap_increase: 263 stable_memory_increase: 256 scopes: icrc103_get_allowances: calls: 1 - instructions: 5652590 + instructions: 5652628 heap_increase: 0 stable_memory_increase: 0 icrc1_transfer: calls: 1 - instructions: 12277234966 + instructions: 12277125048 heap_increase: 34 stable_memory_increase: 0 icrc2_approve: calls: 1 - instructions: 18497580928 + instructions: 18496271005 heap_increase: 25 stable_memory_increase: 128 icrc2_transfer_from: calls: 1 - instructions: 20649025716 + instructions: 20648355831 heap_increase: 3 stable_memory_increase: 0 icrc3_get_blocks: @@ -33,39 +33,39 @@ benches: stable_memory_increase: 0 post_upgrade: calls: 1 - instructions: 351211421 + instructions: 342206912 heap_increase: 72 stable_memory_increase: 0 pre_upgrade: calls: 1 - instructions: 148925235 + instructions: 149978847 heap_increase: 129 stable_memory_increase: 128 upgrade: calls: 1 - instructions: 500139397 + instructions: 492188500 heap_increase: 201 stable_memory_increase: 128 bench_upgrade_baseline: total: calls: 1 - instructions: 8696311 + instructions: 8691827 heap_increase: 258 stable_memory_increase: 128 scopes: post_upgrade: calls: 1 - instructions: 8613896 + instructions: 8609300 heap_increase: 129 stable_memory_increase: 0 pre_upgrade: calls: 1 - instructions: 79491 + instructions: 79603 heap_increase: 129 stable_memory_increase: 128 upgrade: calls: 1 - instructions: 8695403 + instructions: 8690919 heap_increase: 258 stable_memory_increase: 128 version: 0.4.1