From c49d406808ffeb5b21edc99439a88be7a7c46fbb Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Thu, 25 Jan 2024 13:53:04 +0000 Subject: [PATCH] feat: [IC-272] add fetch_canister_logs stub to the management canister API --- rs/execution_environment/src/canister_manager.rs | 6 ++++++ .../src/execution_environment.rs | 16 ++++++++++++++-- rs/execution_environment/src/ic00_permissions.rs | 5 +++++ rs/execution_environment/src/scheduler.rs | 1 + rs/system_api/src/routing.rs | 10 ++++++++++ rs/system_api/src/sandbox_safe_system_state.rs | 1 + rs/types/ic00_types/src/lib.rs | 2 ++ rs/types/types/src/messages/ingress_messages.rs | 1 + rs/types/types/src/messages/inter_canister.rs | 1 + 9 files changed, 41 insertions(+), 2 deletions(-) diff --git a/rs/execution_environment/src/canister_manager.rs b/rs/execution_environment/src/canister_manager.rs index 47d88402b8f..505720d397a 100644 --- a/rs/execution_environment/src/canister_manager.rs +++ b/rs/execution_environment/src/canister_manager.rs @@ -531,6 +531,12 @@ impl CanisterManager { } }, + // TODO(IC-272). + Ok(Ic00Method::FetchCanisterLogs) => Err(UserError::new( + ErrorCode::CanisterRejectedMessage, + format!("{} API is not yet implemented", Ic00Method::FetchCanisterLogs) + )), + Ok(Ic00Method::ProvisionalCreateCanisterWithCycles) | Ok(Ic00Method::BitcoinGetSuccessors) | Ok(Ic00Method::ProvisionalTopUpCanister) => { diff --git a/rs/execution_environment/src/execution_environment.rs b/rs/execution_environment/src/execution_environment.rs index 8d4df3a1d02..667f653392c 100644 --- a/rs/execution_environment/src/execution_environment.rs +++ b/rs/execution_environment/src/execution_environment.rs @@ -1086,6 +1086,14 @@ impl ExecutionEnvironment { Some((res, msg.take_cycles())) } + Ok(Ic00Method::DeleteChunks) | Ok(Ic00Method::InstallChunkedCode) => Some(( + Err(UserError::new( + ErrorCode::CanisterRejectedMessage, + "Chunked upload API is not yet implemented.", + )), + msg.take_cycles(), + )), + Ok(Ic00Method::NodeMetricsHistory) => { let res = match NodeMetricsHistoryArgs::decode(payload) { Err(err) => Err(err), @@ -1094,10 +1102,14 @@ impl ExecutionEnvironment { Some((res, msg.take_cycles())) } - Ok(Ic00Method::DeleteChunks) | Ok(Ic00Method::InstallChunkedCode) => Some(( + Ok(Ic00Method::FetchCanisterLogs) => Some(( + // TODO(IC-272). Err(UserError::new( ErrorCode::CanisterRejectedMessage, - "Chunked upload API is not yet implemented.", + format!( + "{} API is not yet implemented.", + Ic00Method::FetchCanisterLogs + ), )), msg.take_cycles(), )), diff --git a/rs/execution_environment/src/ic00_permissions.rs b/rs/execution_environment/src/ic00_permissions.rs index 3e8e4c56dc0..8caf9959928 100644 --- a/rs/execution_environment/src/ic00_permissions.rs +++ b/rs/execution_environment/src/ic00_permissions.rs @@ -138,6 +138,11 @@ impl Ic00MethodPermissions { allow_remote_subnet_sender: true, allow_only_nns_subnet_sender: false, }, + Ic00Method::FetchCanisterLogs => Self { + method, + allow_remote_subnet_sender: false, // Only users can call this method, not canisters (also no nested composite query calls). + allow_only_nns_subnet_sender: false, + }, Ic00Method::ProvisionalCreateCanisterWithCycles => Self { method, allow_remote_subnet_sender: true, diff --git a/rs/execution_environment/src/scheduler.rs b/rs/execution_environment/src/scheduler.rs index 727af307767..3f4edb2baf6 100644 --- a/rs/execution_environment/src/scheduler.rs +++ b/rs/execution_environment/src/scheduler.rs @@ -2338,6 +2338,7 @@ fn get_instructions_limits_for_subnet_message( | BitcoinGetCurrentFeePercentiles | BitcoinGetSuccessors | NodeMetricsHistory + | FetchCanisterLogs | ProvisionalCreateCanisterWithCycles | ProvisionalTopUpCanister | UploadChunk diff --git a/rs/system_api/src/routing.rs b/rs/system_api/src/routing.rs index 7ed9d1b9945..574c02941de 100644 --- a/rs/system_api/src/routing.rs +++ b/rs/system_api/src/routing.rs @@ -177,6 +177,16 @@ pub(super) fn resolve_destination( Ok(Ic00Method::NodeMetricsHistory) => { Ok(NodeMetricsHistoryArgs::decode(payload)?.subnet_id) } + Ok(Ic00Method::FetchCanisterLogs) => { + // TODO(IC-272). + Err(ResolveDestinationError::UserError(UserError::new( + ic_error_types::ErrorCode::CanisterRejectedMessage, + format!( + "{} API is not yet implemented", + Ic00Method::FetchCanisterLogs + ), + ))) + } Ok(Ic00Method::ECDSAPublicKey) => { let key_id = ECDSAPublicKeyArgs::decode(payload)?.key_id; route_ecdsa_message( diff --git a/rs/system_api/src/sandbox_safe_system_state.rs b/rs/system_api/src/sandbox_safe_system_state.rs index 96ad4c9fb3d..4e0681a078e 100644 --- a/rs/system_api/src/sandbox_safe_system_state.rs +++ b/rs/system_api/src/sandbox_safe_system_state.rs @@ -243,6 +243,7 @@ impl SystemStateChanges { | Ok(Ic00Method::BitcoinSendTransaction) | Ok(Ic00Method::BitcoinGetCurrentFeePercentiles) | Ok(Ic00Method::NodeMetricsHistory) + | Ok(Ic00Method::FetchCanisterLogs) | Ok(Ic00Method::UploadChunk) | Ok(Ic00Method::StoredChunks) | Ok(Ic00Method::DeleteChunks) diff --git a/rs/types/ic00_types/src/lib.rs b/rs/types/ic00_types/src/lib.rs index ac49bffb00a..e08d79f1077 100644 --- a/rs/types/ic00_types/src/lib.rs +++ b/rs/types/ic00_types/src/lib.rs @@ -77,6 +77,8 @@ pub enum Method { NodeMetricsHistory, + FetchCanisterLogs, + // These methods are only available on test IC instances where there is a // need to fabricate cycles without burning ICP first. ProvisionalCreateCanisterWithCycles, diff --git a/rs/types/types/src/messages/ingress_messages.rs b/rs/types/types/src/messages/ingress_messages.rs index 34f1cd1e6dd..dca92673b84 100644 --- a/rs/types/types/src/messages/ingress_messages.rs +++ b/rs/types/types/src/messages/ingress_messages.rs @@ -511,6 +511,7 @@ pub fn extract_effective_canister_id( Ok(record) => Ok(Some(record.get_canister_id())), Err(err) => Err(ParseIngressError::InvalidSubnetPayload(err.to_string())), }, + Ok(Method::FetchCanisterLogs) => Err(ParseIngressError::UnknownSubnetMethod), // TODO(IC-272). Ok(Method::DeleteChunks) | Ok(Method::TakeCanisterSnapshot) | Ok(Method::LoadCanisterSnapshot) diff --git a/rs/types/types/src/messages/inter_canister.rs b/rs/types/types/src/messages/inter_canister.rs index 66c3bd9bd98..6c72bd907a4 100644 --- a/rs/types/types/src/messages/inter_canister.rs +++ b/rs/types/types/src/messages/inter_canister.rs @@ -147,6 +147,7 @@ impl Request { Err(_) => None, } } + Ok(Method::FetchCanisterLogs) => None, // TODO(IC-272). Ok(Method::UploadChunk) => match UploadChunkArgs::decode(&self.method_payload) { Ok(record) => Some(record.get_canister_id()), Err(_) => None,