Skip to content

Commit a1a201b

Browse files
feat: EXC:1532: Introduce delete canister snapshot arguments
1 parent 169e8dc commit a1a201b

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

rs/execution_environment/src/execution_environment.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ use ic_logger::{error, info, warn, ReplicaLogger};
3636
use ic_management_canister_types::{
3737
CanisterChangeOrigin, CanisterHttpRequestArgs, CanisterIdRecord, CanisterInfoRequest,
3838
CanisterInfoResponse, CanisterSettingsArgs, CanisterStatusType, ClearChunkStoreArgs,
39-
ComputeInitialEcdsaDealingsArgs, CreateCanisterArgs, ECDSAPublicKeyArgs,
40-
ECDSAPublicKeyResponse, EcdsaKeyId, EmptyBlob, InstallChunkedCodeArgs, InstallCodeArgsV2,
41-
Method as Ic00Method, NodeMetricsHistoryArgs, Payload as Ic00Payload,
39+
ComputeInitialEcdsaDealingsArgs, CreateCanisterArgs, DeleteCanisterSnapshotArgs,
40+
ECDSAPublicKeyArgs, ECDSAPublicKeyResponse, EcdsaKeyId, EmptyBlob, InstallChunkedCodeArgs,
41+
InstallCodeArgsV2, Method as Ic00Method, NodeMetricsHistoryArgs, Payload as Ic00Payload,
4242
ProvisionalCreateCanisterWithCyclesArgs, ProvisionalTopUpCanisterArgs, SetupInitialDKGArgs,
4343
SignWithECDSAArgs, StoredChunksArgs, TakeCanisterSnapshotArgs, UninstallCodeArgs,
4444
UpdateSettingsArgs, UploadChunkArgs, IC_00,
@@ -1320,12 +1320,18 @@ impl ExecutionEnvironment {
13201320

13211321
Ok(Ic00Method::DeleteCanisterSnapshot) => match self.config.canister_snapshots {
13221322
FlagStatus::Enabled => {
1323-
// TODO(EXC-1532): Implement delete_canister_snapshot.
1323+
let res = match DeleteCanisterSnapshotArgs::decode(payload) {
1324+
Err(err) => Err(err),
1325+
Ok(_) => {
1326+
// TODO(EXC-1532): Implement delete_canister_snapshot.
1327+
Err(UserError::new(
1328+
ErrorCode::CanisterRejectedMessage,
1329+
"Canister snapshotting API is not yet implemented.",
1330+
))
1331+
}
1332+
};
13241333
ExecuteSubnetMessageResult::Finished {
1325-
response: Err(UserError::new(
1326-
ErrorCode::CanisterRejectedMessage,
1327-
"Canister snapshotting API is not yet implemented.",
1328-
)),
1334+
response: res,
13291335
refund: msg.take_cycles(),
13301336
}
13311337
}

rs/execution_environment/src/execution_environment/tests/canister_snapshots.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use candid::Encode;
33
use ic_config::flag_status::FlagStatus;
44
use ic_error_types::RejectCode;
55
use ic_management_canister_types::{
6-
self as ic00, Method, Payload as Ic00Payload, TakeCanisterSnapshotArgs,
7-
TakeCanisterSnapshotResponse,
6+
self as ic00, DeleteCanisterSnapshotArgs, Method, Payload as Ic00Payload,
7+
TakeCanisterSnapshotArgs, TakeCanisterSnapshotResponse,
88
};
99
use ic_replicated_state::canister_snapshots::SnapshotId;
1010
use ic_test_utilities_execution_environment::{get_output_messages, ExecutionTestBuilder};
@@ -168,3 +168,14 @@ fn test_ingress_snapshot_rejected_because_feature_is_disabled() {
168168
assert_eq!(result, expected_result);
169169
}
170170
}
171+
172+
#[test]
173+
fn test_delete_canister_snapshot_decode_round_trip() {
174+
let snapshot_id = SnapshotId::new(6);
175+
let args = ic00::DeleteCanisterSnapshotArgs::new(canister_test_id(4), snapshot_id.get());
176+
let encoded_args = args.encode();
177+
assert_eq!(
178+
args,
179+
DeleteCanisterSnapshotArgs::decode(encoded_args.as_slice()).unwrap()
180+
);
181+
}

rs/types/management_canister_types/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,3 +2708,33 @@ impl TakeCanisterSnapshotResponse {
27082708
}
27092709
}
27102710
}
2711+
2712+
/// Struct used for encoding/decoding
2713+
/// `(record {
2714+
/// canister_id: principal;
2715+
/// snapshot_id: nat;
2716+
/// })`
2717+
#[derive(Default, Clone, CandidType, Deserialize, Debug, PartialEq, Eq)]
2718+
pub struct DeleteCanisterSnapshotArgs {
2719+
pub canister_id: PrincipalId,
2720+
pub snapshot_id: candid::Nat,
2721+
}
2722+
2723+
impl Payload<'_> for DeleteCanisterSnapshotArgs {}
2724+
2725+
impl DeleteCanisterSnapshotArgs {
2726+
pub fn new(canister_id: CanisterId, snapshot_id: u64) -> Self {
2727+
Self {
2728+
canister_id: canister_id.get(),
2729+
snapshot_id: candid::Nat::from(snapshot_id),
2730+
}
2731+
}
2732+
2733+
pub fn get_canister_id(&self) -> CanisterId {
2734+
CanisterId::unchecked_from_principal(self.canister_id)
2735+
}
2736+
2737+
pub fn get_snapshot_id(&self) -> u64 {
2738+
self.snapshot_id.0.to_u64().unwrap()
2739+
}
2740+
}

0 commit comments

Comments
 (0)