Skip to content

Commit

Permalink
fix(RUN-915): Change stored_chunks return type
Browse files Browse the repository at this point in the history
  • Loading branch information
adambratschikaye committed Feb 15, 2024
1 parent 94e1d81 commit 0fcf6c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions rs/execution_environment/src/canister_manager.rs
Expand Up @@ -21,7 +21,7 @@ use ic_interfaces::execution_environment::{
use ic_logger::{error, fatal, info, ReplicaLogger};
use ic_management_canister_types::{
CanisterChangeDetails, CanisterChangeOrigin, CanisterInstallModeV2, CanisterStatusResultV2,
CanisterStatusType, InstallChunkedCodeArgs, InstallCodeArgsV2, Method as Ic00Method,
CanisterStatusType, ChunkHash, InstallChunkedCodeArgs, InstallCodeArgsV2, Method as Ic00Method,
StoredChunksReply, UploadChunkReply,
};
use ic_registry_provisional_whitelist::ProvisionalWhitelist;
Expand Down Expand Up @@ -1800,7 +1800,7 @@ impl CanisterManager {
.system_state
.wasm_chunk_store
.keys()
.map(|k| serde_bytes::ByteBuf::from(*k))
.map(|k| ChunkHash { hash: k.to_vec() })
.collect();
Ok(StoredChunksReply(keys))
}
Expand Down
24 changes: 17 additions & 7 deletions rs/execution_environment/src/canister_manager/tests.rs
Expand Up @@ -25,9 +25,9 @@ use ic_logger::replica_logger::no_op_logger;
use ic_management_canister_types::{
CanisterChange, CanisterChangeDetails, CanisterChangeOrigin, CanisterIdRecord,
CanisterInstallMode, CanisterInstallModeV2, CanisterSettingsArgsBuilder,
CanisterStatusResultV2, CanisterStatusType, ClearChunkStoreArgs, CreateCanisterArgs, EmptyBlob,
InstallCodeArgsV2, Method, Payload, SkipPreUpgrade, StoredChunksArgs, StoredChunksReply,
UpdateSettingsArgs, UploadChunkArgs, UploadChunkReply,
CanisterStatusResultV2, CanisterStatusType, ChunkHash, ClearChunkStoreArgs, CreateCanisterArgs,
EmptyBlob, InstallCodeArgsV2, Method, Payload, SkipPreUpgrade, StoredChunksArgs,
StoredChunksReply, UpdateSettingsArgs, UploadChunkArgs, UploadChunkReply,
};
use ic_metrics::MetricsRegistry;
use ic_registry_provisional_whitelist::ProvisionalWhitelist;
Expand Down Expand Up @@ -7385,8 +7385,6 @@ fn clear_chunk_store_works() {

#[test]
fn stored_chunks_works() {
use serde_bytes::ByteBuf;

const CYCLES: Cycles = Cycles::new(1_000_000_000_000_000);

let mut test = ExecutionTestBuilder::new()
Expand Down Expand Up @@ -7440,7 +7438,12 @@ fn stored_chunks_works() {
StoredChunksReply
)
.unwrap();
assert_eq!(reply, StoredChunksReply(vec![ByteBuf::from(hash1)]));
assert_eq!(
reply,
StoredChunksReply(vec![ChunkHash {
hash: hash1.to_vec()
}])
);

// Then two chunks
test.subnet_message(
Expand All @@ -7466,7 +7469,14 @@ fn stored_chunks_works() {
StoredChunksReply
)
.unwrap();
let mut expected = vec![ByteBuf::from(hash1), ByteBuf::from(hash2)];
let mut expected = vec![
ChunkHash {
hash: hash1.to_vec(),
},
ChunkHash {
hash: hash2.to_vec(),
},
];
expected.sort();
assert_eq!(reply, StoredChunksReply(expected));
}
Expand Down
18 changes: 12 additions & 6 deletions rs/types/management_canister_types/src/lib.rs
Expand Up @@ -2410,17 +2410,23 @@ impl UploadChunkArgs {
}
}

/// Struct to be returned when uploading a Wasm chunk.
/// Candid type representing the hash of a wasm chunk.
/// `(record {
/// hash: blob;
/// })`
#[derive(CandidType, Deserialize, Debug)]
pub struct UploadChunkReply {
#[derive(CandidType, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct ChunkHash {
#[serde(with = "serde_bytes")]
pub hash: Vec<u8>,
}

impl Payload<'_> for UploadChunkReply {}
impl Payload<'_> for ChunkHash {}

/// Struct to be returned when uploading a Wasm chunk.
/// `(record {
/// hash: blob;
/// })`
pub type UploadChunkReply = ChunkHash;

/// Struct used for encoding/decoding
/// `(record {
Expand Down Expand Up @@ -2536,8 +2542,8 @@ impl StoredChunksArgs {
}

/// Struct to be returned when listing chunks in the Wasm store
/// `(vec blob)`
/// `(vec record { hash: blob })`
#[derive(CandidType, Deserialize, Debug, PartialEq)]
pub struct StoredChunksReply(pub Vec<serde_bytes::ByteBuf>);
pub struct StoredChunksReply(pub Vec<ChunkHash>);

impl Payload<'_> for StoredChunksReply {}

0 comments on commit 0fcf6c1

Please sign in to comment.