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: add log_visibility_v2 #674

Draft
wants to merge 78 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9297943
allow list
maksymar Jul 25, 2024
baed06d
.
maksymar Jul 25, 2024
f2c9478
Merge branch 'master' into maksym/allow-log-visibility
maksymar Jul 29, 2024
d48ab79
v2
maksymar Jul 29, 2024
5364bf8
.
maksymar Jul 29, 2024
b8025f2
LogVisibilityEnum
maksymar Jul 29, 2024
a2d4d79
try_from
maksymar Jul 29, 2024
187f4fc
.
maksymar Jul 29, 2024
e5effbf
.
maksymar Jul 29, 2024
e6804fb
from
maksymar Jul 29, 2024
bc1cd80
.
maksymar Jul 29, 2024
e69a0fc
.
maksymar Jul 29, 2024
7a96f2c
cleanup
maksymar Jul 29, 2024
a1897a6
save log_visibility_v2
maksymar Jul 29, 2024
59bdf00
remove log_visibility_v2
maksymar Jul 29, 2024
1fb3f99
.
maksymar Jul 29, 2024
bf19486
.
maksymar Jul 29, 2024
d6f7ceb
.
maksymar Jul 29, 2024
a77a1ae
cleanup
maksymar Jul 29, 2024
33f0acc
cleanup
maksymar Jul 29, 2024
8d15350
remove empty allowed controllers
maksymar Jul 29, 2024
ca91f9f
clippy
maksymar Jul 29, 2024
3b0e1d3
fix test
maksymar Jul 29, 2024
d616230
clippy
maksymar Jul 29, 2024
3e9bc7e
clippy
maksymar Jul 29, 2024
11bb25e
clippy
maksymar Jul 29, 2024
10371eb
cleanup
maksymar Jul 29, 2024
ebf4957
nns cmc.did
maksymar Jul 30, 2024
884de87
Merge branch 'master' into maksym/allow-log-visibility
maksymar Jul 30, 2024
125274c
add log_visibility_v2
maksymar Jul 30, 2024
2e58b40
.
maksymar Jul 30, 2024
e9789f2
add log_visibility_v2
maksymar Jul 30, 2024
8a3ed65
merge reabase
maksymar Jul 30, 2024
c99ee10
merge
maksymar Jul 30, 2024
aa4546d
cleanup
maksymar Jul 30, 2024
eab303f
cleanup
maksymar Jul 30, 2024
14d8484
proto cleanup
maksymar Jul 30, 2024
03a9fc5
allow list
maksymar Jul 25, 2024
610cd56
.
maksymar Jul 25, 2024
749b49a
v2
maksymar Jul 29, 2024
27e6ee0
.
maksymar Jul 29, 2024
2826114
LogVisibilityEnum
maksymar Jul 29, 2024
24ee005
try_from
maksymar Jul 29, 2024
33ef12c
.
maksymar Jul 29, 2024
f81523a
.
maksymar Jul 29, 2024
cd4692f
from
maksymar Jul 29, 2024
dc8e5f2
.
maksymar Jul 29, 2024
b327ea4
.
maksymar Jul 29, 2024
0acdc2f
cleanup
maksymar Jul 29, 2024
b4411b1
save log_visibility_v2
maksymar Jul 29, 2024
a29ea2e
remove log_visibility_v2
maksymar Jul 29, 2024
422ef42
.
maksymar Jul 29, 2024
91b30ed
.
maksymar Jul 29, 2024
cca42fb
.
maksymar Jul 29, 2024
5ccb791
cleanup
maksymar Jul 29, 2024
d432375
cleanup
maksymar Jul 29, 2024
063b49e
remove empty allowed controllers
maksymar Jul 29, 2024
138716f
clippy
maksymar Jul 29, 2024
70f374c
fix test
maksymar Jul 29, 2024
10d577f
clippy
maksymar Jul 29, 2024
5409d94
clippy
maksymar Jul 29, 2024
c23a9a5
clippy
maksymar Jul 29, 2024
d6e4893
cleanup
maksymar Jul 29, 2024
7bc11a4
nns cmc.did
maksymar Jul 30, 2024
80cb29a
add log_visibility_v2
maksymar Jul 30, 2024
fe2cc6d
merge reabase
maksymar Jul 30, 2024
3588a9b
rebase master
maksymar Jul 30, 2024
bd926a4
cleanup
maksymar Jul 30, 2024
5412e8d
cleanup
maksymar Jul 30, 2024
57b20da
proto cleanup
maksymar Jul 30, 2024
3a03441
rebase
maksymar Jul 30, 2024
05fea6b
revert cleanup
maksymar Jul 30, 2024
fd00cd2
.
maksymar Jul 30, 2024
96268d6
.
maksymar Jul 30, 2024
a39c5ea
as_ref
maksymar Jul 30, 2024
c9d6581
add allowed_viewers
maksymar Jul 30, 2024
a901f90
fix test
maksymar Jul 30, 2024
504d971
fix build & test
maksymar Jul 30, 2024
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
4 changes: 2 additions & 2 deletions rs/execution_environment/src/canister_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ impl CanisterManager {
canister.system_state.freeze_threshold = freezing_threshold;
}
if let Some(log_visibility) = settings.log_visibility() {
canister.system_state.log_visibility = log_visibility;
canister.system_state.log_visibility = log_visibility.clone();
}
if let Some(wasm_memory_limit) = settings.wasm_memory_limit() {
canister.system_state.wasm_memory_limit = Some(wasm_memory_limit);
Expand Down Expand Up @@ -1157,7 +1157,7 @@ impl CanisterManager {
let memory_allocation = canister.memory_allocation();
let freeze_threshold = canister.system_state.freeze_threshold;
let reserved_cycles_limit = canister.system_state.reserved_balance_limit();
let log_visibility = canister.system_state.log_visibility;
let log_visibility = canister.system_state.log_visibility.clone();
let wasm_memory_limit = canister.system_state.wasm_memory_limit;

Ok(CanisterStatusResultV2::new(
Expand Down
10 changes: 5 additions & 5 deletions rs/execution_environment/src/canister_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl CanisterSettings {
self.reserved_cycles_limit
}

pub fn log_visibility(&self) -> Option<LogVisibility> {
self.log_visibility
pub fn log_visibility(&self) -> Option<&LogVisibility> {
self.log_visibility.as_ref()
}

pub fn wasm_memory_limit(&self) -> Option<NumBytes> {
Expand Down Expand Up @@ -381,8 +381,8 @@ impl ValidatedCanisterSettings {
self.reservation_cycles
}

pub fn log_visibility(&self) -> Option<LogVisibility> {
self.log_visibility
pub fn log_visibility(&self) -> Option<&LogVisibility> {
self.log_visibility.as_ref()
}

pub fn wasm_memory_limit(&self) -> Option<NumBytes> {
Expand Down Expand Up @@ -592,7 +592,7 @@ pub(crate) fn validate_canister_settings(
freezing_threshold: settings.freezing_threshold(),
reserved_cycles_limit: settings.reserved_cycles_limit(),
reservation_cycles,
log_visibility: settings.log_visibility(),
log_visibility: settings.log_visibility().cloned(),
wasm_memory_limit: settings.wasm_memory_limit(),
})
}
6 changes: 3 additions & 3 deletions rs/execution_environment/src/execution_environment/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ fn test_canister_settings_log_visibility_default_controllers() {
// Assert.
assert_eq!(
canister_status.settings().log_visibility(),
LogVisibility::Controllers
&LogVisibility::Controllers
);
}

Expand All @@ -3539,7 +3539,7 @@ fn test_canister_settings_log_visibility_create_with_settings() {
// Assert.
assert_eq!(
canister_status.settings().log_visibility(),
LogVisibility::Public
&LogVisibility::Public
);
}

Expand All @@ -3556,7 +3556,7 @@ fn test_canister_settings_log_visibility_set_to_public() {
// Assert.
assert_eq!(
canister_status.settings().log_visibility(),
LogVisibility::Public
&LogVisibility::Public
);
}

Expand Down
3 changes: 2 additions & 1 deletion rs/execution_environment/src/query_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ fn fetch_canister_logs(

match canister.log_visibility() {
LogVisibility::Public => Ok(()),
LogVisibility::AllowedViewers(_) if canister.controllers().contains(&sender) => Ok(()),
LogVisibility::Controllers if canister.controllers().contains(&sender) => Ok(()),
LogVisibility::Controllers => Err(UserError::new(
LogVisibility::AllowedViewers(_) | LogVisibility::Controllers => Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"Caller {} is not allowed to query ic00 method {}",
Expand Down
1 change: 1 addition & 0 deletions rs/nns/cmc/cmc.did
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type BlockIndex = nat64;
type log_visibility = variant {
controllers;
public;
allowed_viewers : vec principal;
};
type CanisterSettings = record {
controllers : opt vec principal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,27 @@ message WasmChunkStoreMetadata {
uint64 size = 2;
}

// TODO(EXC-1670): Migrate to LogVisibilityV2.
// The current enum only supports i32 values, which limits the
// storage of allowed_viewers principals. LogVisibilityV2 will
// support both enum values and a list of principals.
enum LogVisibility {
LOG_VISIBILITY_UNSPECIFIED = 0;
LOG_VISIBILITY_CONTROLLERS = 1;
LOG_VISIBILITY_PUBLIC = 2;
LOG_VISIBILITY_EMPTY_ALLOWED_VIEWERS = 3;
}

enum LogVisibilityEnum {
LOG_VISIBILITY_ENUM_UNSPECIFIED = 0;
LOG_VISIBILITY_ENUM_CONTROLLERS = 1;
LOG_VISIBILITY_ENUM_ALLOWED_VIEWERS = 2;
LOG_VISIBILITY_ENUM_PUBLIC = 3;
}

message LogVisibilityV2 {
LogVisibilityEnum log_visibility_enum = 1;
repeated types.v1.PrincipalId allowed_viewers = 2;
}

message CanisterLogRecord {
Expand Down Expand Up @@ -403,7 +420,7 @@ message CanisterStateBits {
// Statistics on query execution for entire lifetime of canister.
TotalQueryStats total_query_stats = 41;
// Log visibility for the canister.
LogVisibility log_visibility = 42;
LogVisibility log_visibility = 42; // TODO(EXC-1670): remove this field.
// Log records of the canister.
repeated CanisterLogRecord canister_log_records = 43;
// The index of the next log record to be created.
Expand All @@ -419,4 +436,6 @@ message CanisterStateBits {
int64 priority_credit = 48;
LongExecutionMode long_execution_mode = 49;
optional uint64 wasm_memory_threshold = 50;
// Log visibility for the canister.
LogVisibilityV2 log_visibility_v2 = 51;
}
52 changes: 52 additions & 0 deletions rs/protobuf/src/gen/state/state.canister_state_bits.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ pub struct WasmChunkStoreMetadata {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LogVisibilityV2 {
#[prost(enumeration = "LogVisibilityEnum", tag = "1")]
pub log_visibility_enum: i32,
#[prost(message, repeated, tag = "2")]
pub allowed_viewers: ::prost::alloc::vec::Vec<super::super::super::types::v1::PrincipalId>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CanisterLogRecord {
#[prost(uint64, tag = "1")]
pub idx: u64,
Expand Down Expand Up @@ -647,6 +655,8 @@ pub struct CanisterStateBits {
#[prost(message, optional, tag = "41")]
pub total_query_stats: ::core::option::Option<TotalQueryStats>,
/// Log visibility for the canister.
///
/// TODO(EXC-1670): remove this field.
#[prost(enumeration = "LogVisibility", tag = "42")]
pub log_visibility: i32,
/// Log records of the canister.
Expand All @@ -670,6 +680,9 @@ pub struct CanisterStateBits {
pub long_execution_mode: i32,
#[prost(uint64, optional, tag = "50")]
pub wasm_memory_threshold: ::core::option::Option<u64>,
/// Log visibility for the canister.
#[prost(message, optional, tag = "51")]
pub log_visibility_v2: ::core::option::Option<LogVisibilityV2>,
#[prost(oneof = "canister_state_bits::CanisterStatus", tags = "11, 12, 13")]
pub canister_status: ::core::option::Option<canister_state_bits::CanisterStatus>,
}
Expand Down Expand Up @@ -813,12 +826,17 @@ impl CyclesUseCase {
}
}
}
/// TODO(EXC-1670): Migrate to LogVisibilityV2.
/// The current enum only supports i32 values, which limits the
/// storage of allowed_viewers principals. LogVisibilityV2 will
/// support both enum values and a list of principals.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LogVisibility {
Unspecified = 0,
Controllers = 1,
Public = 2,
EmptyAllowedViewers = 3,
}
impl LogVisibility {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -830,6 +848,7 @@ impl LogVisibility {
LogVisibility::Unspecified => "LOG_VISIBILITY_UNSPECIFIED",
LogVisibility::Controllers => "LOG_VISIBILITY_CONTROLLERS",
LogVisibility::Public => "LOG_VISIBILITY_PUBLIC",
LogVisibility::EmptyAllowedViewers => "LOG_VISIBILITY_EMPTY_ALLOWED_VIEWERS",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -838,6 +857,39 @@ impl LogVisibility {
"LOG_VISIBILITY_UNSPECIFIED" => Some(Self::Unspecified),
"LOG_VISIBILITY_CONTROLLERS" => Some(Self::Controllers),
"LOG_VISIBILITY_PUBLIC" => Some(Self::Public),
"LOG_VISIBILITY_EMPTY_ALLOWED_VIEWERS" => Some(Self::EmptyAllowedViewers),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LogVisibilityEnum {
Unspecified = 0,
Controllers = 1,
AllowedViewers = 2,
Public = 3,
}
impl LogVisibilityEnum {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
LogVisibilityEnum::Unspecified => "LOG_VISIBILITY_ENUM_UNSPECIFIED",
LogVisibilityEnum::Controllers => "LOG_VISIBILITY_ENUM_CONTROLLERS",
LogVisibilityEnum::AllowedViewers => "LOG_VISIBILITY_ENUM_ALLOWED_VIEWERS",
LogVisibilityEnum::Public => "LOG_VISIBILITY_ENUM_PUBLIC",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"LOG_VISIBILITY_ENUM_UNSPECIFIED" => Some(Self::Unspecified),
"LOG_VISIBILITY_ENUM_CONTROLLERS" => Some(Self::Controllers),
"LOG_VISIBILITY_ENUM_ALLOWED_VIEWERS" => Some(Self::AllowedViewers),
"LOG_VISIBILITY_ENUM_PUBLIC" => Some(Self::Public),
_ => None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions rs/replicated_state/src/canister_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl CanisterState {
&self.system_state.controllers
}

pub fn log_visibility(&self) -> LogVisibility {
self.system_state.log_visibility
pub fn log_visibility(&self) -> &LogVisibility {
&self.system_state.log_visibility
}

/// Returns the difference in time since the canister was last charged for resource allocations.
Expand Down
14 changes: 8 additions & 6 deletions rs/replicated_state/src/canister_state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ fn canister_state_log_visibility_round_trip() {

assert_eq!(initial, round_trip);
}

for initial in LogVisibility::iter() {
let encoded = pb::LogVisibilityV2::from(&initial);
let round_trip = LogVisibility::from(encoded);

assert_eq!(initial, round_trip);
}
}

#[test]
Expand Down Expand Up @@ -657,12 +664,7 @@ fn long_execution_mode_decoding() {
fn compatibility_for_log_visibility() {
// If this fails, you are making a potentially incompatible change to `LogVisibility`.
// See note [Handling changes to Enums in Replicated State] for how to proceed.
assert_eq!(
LogVisibility::iter()
.map(|x| x as i32)
.collect::<Vec<i32>>(),
[1, 2]
);
assert_eq!(LogVisibility::iter().count(), 3);
}

#[test]
Expand Down
33 changes: 22 additions & 11 deletions rs/state_layout/src/state_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,8 @@ impl From<CanisterStateBits> for pb_canister_state_bits::CanisterStateBits {
next_canister_log_record_idx: item.canister_log.next_idx(),
wasm_memory_limit: item.wasm_memory_limit.map(|v| v.get()),
next_snapshot_id: item.next_snapshot_id,
log_visibility_v2: pb_canister_state_bits::LogVisibilityV2::from(&item.log_visibility)
.into(),
}
}
}
Expand Down Expand Up @@ -2016,6 +2018,25 @@ impl TryFrom<pb_canister_state_bits::CanisterStateBits> for CanisterStateBits {
);
}

// TODO(EXC-1670): remove after migration to `pb_canister_state_bits::LogVisibilityV2`.
// First try to decode `log_visibility_v2` and if it fails, fallback to `log_visibility`.
// This should populate `allowed_viewers` correctly with the list of principals.
let log_visibility: LogVisibility = match try_from_option_field(
value.log_visibility_v2,
"CanisterStateBits::log_visibility_v2",
) {
Ok(log_visibility_v2) => log_visibility_v2,
Err(_) => pb_canister_state_bits::LogVisibility::try_from(value.log_visibility)
.map_err(|_| ProxyDecodeError::ValueOutOfRange {
typ: "LogVisibility",
err: format!(
"Unexpected value of log visibility: {}",
value.log_visibility
),
})?
.into(),
};

Ok(Self {
controllers,
last_full_execution_round: value.last_full_execution_round.into(),
Expand Down Expand Up @@ -2082,17 +2103,7 @@ impl TryFrom<pb_canister_state_bits::CanisterStateBits> for CanisterStateBits {
"CanisterStateBits::total_query_stats",
)
.unwrap_or_default(),
log_visibility: LogVisibility::from(
pb_canister_state_bits::LogVisibility::try_from(value.log_visibility).map_err(
|_| ProxyDecodeError::ValueOutOfRange {
typ: "LogVisibility",
err: format!(
"Unexpected value of log visibility: {}",
value.log_visibility
),
},
)?,
),
log_visibility,
canister_log: CanisterLog::new(
value.next_canister_log_record_idx,
value
Expand Down
2 changes: 1 addition & 1 deletion rs/state_manager/src/tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ fn serialize_canister_to_tip(
.metadata()
.clone(),
total_query_stats: canister_state.scheduler_state.total_query_stats.clone(),
log_visibility: canister_state.system_state.log_visibility,
log_visibility: canister_state.system_state.log_visibility.clone(),
canister_log: canister_state.system_state.canister_log.clone(),
wasm_memory_limit: canister_state.system_state.wasm_memory_limit,
next_snapshot_id: canister_state.system_state.next_snapshot_id,
Expand Down
2 changes: 1 addition & 1 deletion rs/types/management_canister_types/src/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub const UNBOUNDED: usize = usize::MAX;
/// - number of elements
/// - total data size in bytes
/// - single element data size in bytes
#[derive(CandidType, Debug, Clone, PartialEq, Eq)]
#[derive(CandidType, Debug, Clone, PartialEq, Eq, Default)]
pub struct BoundedVec<
const MAX_ALLOWED_LEN: usize,
const MAX_ALLOWED_TOTAL_DATA_SIZE: usize,
Expand Down
Loading