Skip to content

Commit

Permalink
feat: EXC:1532: Introduce delete canister snapshot arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraZapuc committed Mar 12, 2024
1 parent 169e8dc commit a1a201b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
22 changes: 14 additions & 8 deletions rs/execution_environment/src/execution_environment.rs
Expand Up @@ -36,9 +36,9 @@ use ic_logger::{error, info, warn, ReplicaLogger};
use ic_management_canister_types::{
CanisterChangeOrigin, CanisterHttpRequestArgs, CanisterIdRecord, CanisterInfoRequest,
CanisterInfoResponse, CanisterSettingsArgs, CanisterStatusType, ClearChunkStoreArgs,
ComputeInitialEcdsaDealingsArgs, CreateCanisterArgs, ECDSAPublicKeyArgs,
ECDSAPublicKeyResponse, EcdsaKeyId, EmptyBlob, InstallChunkedCodeArgs, InstallCodeArgsV2,
Method as Ic00Method, NodeMetricsHistoryArgs, Payload as Ic00Payload,
ComputeInitialEcdsaDealingsArgs, CreateCanisterArgs, DeleteCanisterSnapshotArgs,
ECDSAPublicKeyArgs, ECDSAPublicKeyResponse, EcdsaKeyId, EmptyBlob, InstallChunkedCodeArgs,
InstallCodeArgsV2, Method as Ic00Method, NodeMetricsHistoryArgs, Payload as Ic00Payload,
ProvisionalCreateCanisterWithCyclesArgs, ProvisionalTopUpCanisterArgs, SetupInitialDKGArgs,
SignWithECDSAArgs, StoredChunksArgs, TakeCanisterSnapshotArgs, UninstallCodeArgs,
UpdateSettingsArgs, UploadChunkArgs, IC_00,
Expand Down Expand Up @@ -1320,12 +1320,18 @@ impl ExecutionEnvironment {

Ok(Ic00Method::DeleteCanisterSnapshot) => match self.config.canister_snapshots {
FlagStatus::Enabled => {
// TODO(EXC-1532): Implement delete_canister_snapshot.
let res = match DeleteCanisterSnapshotArgs::decode(payload) {
Err(err) => Err(err),
Ok(_) => {
// TODO(EXC-1532): Implement delete_canister_snapshot.
Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
"Canister snapshotting API is not yet implemented.",
))
}
};
ExecuteSubnetMessageResult::Finished {
response: Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
"Canister snapshotting API is not yet implemented.",
)),
response: res,
refund: msg.take_cycles(),
}
}
Expand Down
Expand Up @@ -3,8 +3,8 @@ use candid::Encode;
use ic_config::flag_status::FlagStatus;
use ic_error_types::RejectCode;
use ic_management_canister_types::{
self as ic00, Method, Payload as Ic00Payload, TakeCanisterSnapshotArgs,
TakeCanisterSnapshotResponse,
self as ic00, DeleteCanisterSnapshotArgs, Method, Payload as Ic00Payload,
TakeCanisterSnapshotArgs, TakeCanisterSnapshotResponse,
};
use ic_replicated_state::canister_snapshots::SnapshotId;
use ic_test_utilities_execution_environment::{get_output_messages, ExecutionTestBuilder};
Expand Down Expand Up @@ -168,3 +168,14 @@ fn test_ingress_snapshot_rejected_because_feature_is_disabled() {
assert_eq!(result, expected_result);
}
}

#[test]
fn test_delete_canister_snapshot_decode_round_trip() {
let snapshot_id = SnapshotId::new(6);
let args = ic00::DeleteCanisterSnapshotArgs::new(canister_test_id(4), snapshot_id.get());
let encoded_args = args.encode();
assert_eq!(
args,
DeleteCanisterSnapshotArgs::decode(encoded_args.as_slice()).unwrap()
);
}
30 changes: 30 additions & 0 deletions rs/types/management_canister_types/src/lib.rs
Expand Up @@ -2708,3 +2708,33 @@ impl TakeCanisterSnapshotResponse {
}
}
}

/// Struct used for encoding/decoding
/// `(record {
/// canister_id: principal;
/// snapshot_id: nat;
/// })`
#[derive(Default, Clone, CandidType, Deserialize, Debug, PartialEq, Eq)]
pub struct DeleteCanisterSnapshotArgs {
pub canister_id: PrincipalId,
pub snapshot_id: candid::Nat,
}

impl Payload<'_> for DeleteCanisterSnapshotArgs {}

impl DeleteCanisterSnapshotArgs {
pub fn new(canister_id: CanisterId, snapshot_id: u64) -> Self {
Self {
canister_id: canister_id.get(),
snapshot_id: candid::Nat::from(snapshot_id),
}
}

pub fn get_canister_id(&self) -> CanisterId {
CanisterId::unchecked_from_principal(self.canister_id)
}

pub fn get_snapshot_id(&self) -> u64 {
self.snapshot_id.0.to_u64().unwrap()
}
}

0 comments on commit a1a201b

Please sign in to comment.