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

feat: support log_visibility canister setting #497

Merged
merged 3 commits into from
Jun 27, 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
1 change: 1 addition & 0 deletions e2e-tests/canisters/canister_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions e2e-tests/canisters/management_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}),
};
Expand All @@ -37,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
Expand Down Expand Up @@ -72,6 +77,7 @@ mod main {

mod provisional {
use super::*;
use api::management_canister::main::LogVisibility;
use ic_cdk::api::management_canister::provisional::*;

#[update]
Expand All @@ -82,6 +88,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 {
Expand Down
2 changes: 2 additions & 0 deletions src/ic-cdk-bindgen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions src/ic-cdk/src/api/management_canister/main/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ 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,
)]
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,
}

/// Canister settings.
///
/// The settings are optional. If they are not explicitly set, the default values will be applied automatically.
Expand Down Expand Up @@ -52,6 +66,10 @@ pub struct CanisterSettings {
///
/// Default value: 5_000_000_000_000 (5 trillion cycles).
pub reserved_cycles_limit: Option<Nat>,
/// Defines who is allowed to read the canister's logs.
///
/// Default value: Controllers
pub log_visibility: Option<LogVisibility>,
/// Must be a number between 0 and 2<sup>48</sup>-1 (i.e 256TB), inclusively.
///
/// It indicates the upper limit on the WASM heap memory consumption of the canister.
Expand Down Expand Up @@ -317,6 +335,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,
}
Expand Down