From 73c929b89b39f523088e4d61410b41baacae2595 Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Thu, 27 Jun 2024 13:14:11 +0200 Subject: [PATCH 1/3] feat: support log_visibility canister setting --- e2e-tests/canisters/canister_info.rs | 1 + e2e-tests/canisters/management_caller.rs | 3 +++ .../src/api/management_canister/main/types.rs | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/e2e-tests/canisters/canister_info.rs b/e2e-tests/canisters/canister_info.rs index 354d7fa1c..9a4bc2078 100644 --- a/e2e-tests/canisters/canister_info.rs +++ b/e2e-tests/canisters/canister_info.rs @@ -69,6 +69,7 @@ async fn canister_lifecycle() -> Principal { memory_allocation: None, freezing_threshold: None, reserved_cycles_limit: None, + log_visibility: None, wasm_memory_limit: None, }, canister_id: canister_id.canister_id, diff --git a/e2e-tests/canisters/management_caller.rs b/e2e-tests/canisters/management_caller.rs index a5c1f53ca..aee72907b 100644 --- a/e2e-tests/canisters/management_caller.rs +++ b/e2e-tests/canisters/management_caller.rs @@ -18,6 +18,7 @@ mod main { memory_allocation: Some(10000u16.into()), freezing_threshold: Some(u64::MAX.into()), reserved_cycles_limit: Some(u128::MAX.into()), + log_visibility: Some(LogVisibility::Public), wasm_memory_limit: Some((2u64.pow(48) - 1).into()), }), }; @@ -72,6 +73,7 @@ mod main { mod provisional { use super::*; + use api::management_canister::main::LogVisibility; use ic_cdk::api::management_canister::provisional::*; #[update] @@ -82,6 +84,7 @@ mod provisional { memory_allocation: Some(10000u16.into()), freezing_threshold: Some(10000u16.into()), reserved_cycles_limit: Some(10000u16.into()), + log_visibility: Some(LogVisibility::Public), wasm_memory_limit: Some(10000u16.into()), }; let arg = ProvisionalCreateCanisterWithCyclesArgument { diff --git a/src/ic-cdk/src/api/management_canister/main/types.rs b/src/ic-cdk/src/api/management_canister/main/types.rs index ac185fa01..46025c96b 100644 --- a/src/ic-cdk/src/api/management_canister/main/types.rs +++ b/src/ic-cdk/src/api/management_canister/main/types.rs @@ -4,6 +4,19 @@ use serde::{Deserialize, Serialize}; /// Canister ID is Principal. pub type CanisterId = Principal; +/// todo +#[derive( + CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default, +)] +#[serde(rename_all = "lowercase")] +pub enum LogVisibility { + #[default] + /// Only controllers of the canister can access the logs. + Controllers, + /// Everyone is allowed to access the canister's logs. + Public, +} + /// Canister settings. /// /// The settings are optional. If they are not explicitly set, the default values will be applied automatically. @@ -52,6 +65,10 @@ pub struct CanisterSettings { /// /// Default value: 5_000_000_000_000 (5 trillion cycles). pub reserved_cycles_limit: Option, + /// Defines who is allowed to read the canister's logs. + /// + /// Default value: Controllers + pub log_visibility: Option, /// Must be a number between 0 and 248-1 (i.e 256TB), inclusively. /// /// It indicates the upper limit on the WASM heap memory consumption of the canister. @@ -317,6 +334,8 @@ pub struct DefiniteCanisterSettings { pub freezing_threshold: Nat, /// Reserved cycles limit. pub reserved_cycles_limit: Nat, + /// Visibility of canister logs. + pub log_visibility: LogVisibility, /// The Wasm memory limit. pub wasm_memory_limit: Nat, } From 976d5a69d2ad9781aad950c4556b74d8ab02e7f1 Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Thu, 27 Jun 2024 13:17:29 +0200 Subject: [PATCH 2/3] changelog --- e2e-tests/canisters/management_caller.rs | 4 ++++ src/ic-cdk-bindgen/CHANGELOG.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/e2e-tests/canisters/management_caller.rs b/e2e-tests/canisters/management_caller.rs index aee72907b..db662d6b4 100644 --- a/e2e-tests/canisters/management_caller.rs +++ b/e2e-tests/canisters/management_caller.rs @@ -38,6 +38,10 @@ mod main { assert_eq!(definite_canister_setting.memory_allocation, 10000u16); assert_eq!(definite_canister_setting.freezing_threshold, u64::MAX); assert_eq!(definite_canister_setting.reserved_cycles_limit, u128::MAX); + assert_eq!( + definite_canister_setting.log_visibility, + LogVisibility::Public + ); assert_eq!( definite_canister_setting.wasm_memory_limit, 2u64.pow(48) - 1 diff --git a/src/ic-cdk-bindgen/CHANGELOG.md b/src/ic-cdk-bindgen/CHANGELOG.md index 6c1c2941a..6135674ed 100644 --- a/src/ic-cdk-bindgen/CHANGELOG.md +++ b/src/ic-cdk-bindgen/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +- Support canister setting `log_visibility`. + ### Changed - Refactor!: move Rust code generation logic from candid_parser. (#480) From 8ef2351e89ca583c1fa65955cf522fef124ed14d Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Thu, 27 Jun 2024 13:44:14 +0200 Subject: [PATCH 3/3] enums dont work with rename_all? --- src/ic-cdk/src/api/management_canister/main/types.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ic-cdk/src/api/management_canister/main/types.rs b/src/ic-cdk/src/api/management_canister/main/types.rs index 46025c96b..97c284fd3 100644 --- a/src/ic-cdk/src/api/management_canister/main/types.rs +++ b/src/ic-cdk/src/api/management_canister/main/types.rs @@ -8,11 +8,12 @@ pub type CanisterId = Principal; #[derive( CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default, )] -#[serde(rename_all = "lowercase")] pub enum LogVisibility { #[default] + #[serde(rename = "controllers")] /// Only controllers of the canister can access the logs. Controllers, + #[serde(rename = "public")] /// Everyone is allowed to access the canister's logs. Public, }