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(control-panel): support deploying large station WASM #364

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions apps/wallet/src/generated/control-panel/control_panel.did
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,23 @@ type CanDeployStationResult = variant {
Err : ApiError;
};

type WasmModuleExtraChunks = record {
// The asset canister from which the chunks are to be retrieved.
store_canister : principal;
// The list of chunk hashes in the order they should be appended to the wasm module.
chunk_hashes_list : vec blob;
// The hash of the assembled wasm module.
wasm_module_hash : blob;
};

// The canister modules required for the control panel.
type UploadCanisterModulesInput = record {
// The upgrader wasm module to use for the station canister.
upgrader_wasm_module : opt blob;
// The station wasm module to use.
station_wasm_module : opt blob;
// Optional extra chunks of the station canister wasm module.
station_wasm_module_extra_chunks : opt opt WasmModuleExtraChunks;
};

// The result of uploading canister modules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export interface UpdateWaitingListInput {
export type UpdateWaitingListResult = { 'Ok' : null } |
{ 'Err' : ApiError };
export interface UploadCanisterModulesInput {
'station_wasm_module_extra_chunks' : [] | [[] | [WasmModuleExtraChunks]],
'station_wasm_module' : [] | [Uint8Array | number[]],
'upgrader_wasm_module' : [] | [Uint8Array | number[]],
}
Expand All @@ -199,6 +200,11 @@ export type UserSubscriptionStatus = { 'Unsubscribed' : null } |
{ 'Approved' : null } |
{ 'Denylisted' : null } |
{ 'Pending' : null };
export interface WasmModuleExtraChunks {
'wasm_module_hash' : Uint8Array | number[],
'chunk_hashes_list' : Array<Uint8Array | number[]>,
'store_canister' : Principal,
}
export interface WasmModuleRegistryEntryDependency {
'name' : string,
'version' : string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,15 @@ export const idlFactory = ({ IDL }) => {
'Ok' : IDL.Null,
'Err' : ApiError,
});
const WasmModuleExtraChunks = IDL.Record({
'wasm_module_hash' : IDL.Vec(IDL.Nat8),
'chunk_hashes_list' : IDL.Vec(IDL.Vec(IDL.Nat8)),
'store_canister' : IDL.Principal,
});
const UploadCanisterModulesInput = IDL.Record({
'station_wasm_module_extra_chunks' : IDL.Opt(
IDL.Opt(WasmModuleExtraChunks)
),
'station_wasm_module' : IDL.Opt(IDL.Vec(IDL.Nat8)),
'upgrader_wasm_module' : IDL.Opt(IDL.Vec(IDL.Nat8)),
});
Expand Down
11 changes: 11 additions & 0 deletions core/control-panel/api/spec.did
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,23 @@ type CanDeployStationResult = variant {
Err : ApiError;
};

type WasmModuleExtraChunks = record {
// The asset canister from which the chunks are to be retrieved.
store_canister : principal;
// The list of chunk hashes in the order they should be appended to the wasm module.
chunk_hashes_list : vec blob;
// The hash of the assembled wasm module.
wasm_module_hash : blob;
};

// The canister modules required for the control panel.
type UploadCanisterModulesInput = record {
// The upgrader wasm module to use for the station canister.
upgrader_wasm_module : opt blob;
// The station wasm module to use.
station_wasm_module : opt blob;
// Optional extra chunks of the station canister wasm module.
station_wasm_module_extra_chunks : opt opt WasmModuleExtraChunks;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe i've already asked before, but why the opt opt here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's confusing...

The outer opt stands for "do I want to override this field or not". The inner opt stands for "is this WASM chunked or not".

};

// The result of uploading canister modules.
Expand Down
2 changes: 2 additions & 0 deletions core/control-panel/api/src/canister.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use candid::{CandidType, Deserialize};
use orbit_essentials::types::WasmModuleExtraChunks;

#[derive(CandidType, serde::Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct UploadCanisterModulesInput {
#[serde(deserialize_with = "orbit_essentials::deserialize::deserialize_option_blob")]
pub upgrader_wasm_module: Option<Vec<u8>>,
#[serde(deserialize_with = "orbit_essentials::deserialize::deserialize_option_blob")]
pub station_wasm_module: Option<Vec<u8>>,
pub station_wasm_module_extra_chunks: Option<Option<WasmModuleExtraChunks>>,
}
13 changes: 11 additions & 2 deletions core/control-panel/impl/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::core::ic_cdk::api::time;
use crate::SYSTEM_VERSION;
use ic_stable_structures::{storable::Bound, Storable};
use orbit_essentials::storable;
use orbit_essentials::types::Timestamp;
use orbit_essentials::types::{Timestamp, WasmModuleExtraChunks};
use std::borrow::Cow;

#[storable]
Expand All @@ -15,6 +15,9 @@ pub struct CanisterConfig {
/// The station canister wasm module that will be used to deploy new stations.
pub station_wasm_module: Vec<u8>,

/// Optional extra chunks of the station canister wasm module.
pub station_wasm_module_extra_chunks: Option<WasmModuleExtraChunks>,

/// Last time the canister was upgraded or initialized.
pub last_upgrade_timestamp: Timestamp,

Expand All @@ -27,17 +30,23 @@ impl Default for CanisterConfig {
Self {
upgrader_wasm_module: vec![],
station_wasm_module: vec![],
station_wasm_module_extra_chunks: None,
last_upgrade_timestamp: time(),
version: None,
}
}
}

impl CanisterConfig {
pub fn new(upgrader_wasm_module: Vec<u8>, station_wasm_module: Vec<u8>) -> Self {
pub fn new(
upgrader_wasm_module: Vec<u8>,
station_wasm_module: Vec<u8>,
station_wasm_module_extra_chunks: Option<WasmModuleExtraChunks>,
) -> Self {
Self {
upgrader_wasm_module,
station_wasm_module,
station_wasm_module_extra_chunks,
last_upgrade_timestamp: time(),
version: Some(SYSTEM_VERSION.to_string()),
}
Expand Down
6 changes: 3 additions & 3 deletions core/control-panel/impl/src/core/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ mod tests {

#[test]
fn test_canister_config() {
let config = CanisterConfig::new(Vec::new(), Vec::new());
let config = CanisterConfig::new(Vec::new(), Vec::new(), None);
write_canister_config(config.clone());
assert_eq!(canister_config(), Some(config));
}

#[test]
fn test_update_canister_config() {
let config = CanisterConfig::new(Vec::new(), Vec::new());
let config = CanisterConfig::new(Vec::new(), Vec::new(), None);
write_canister_config(config.clone());
let new_config = CanisterConfig::new(vec![1], vec![2]);
let new_config = CanisterConfig::new(vec![1], vec![2], None);
write_canister_config(new_config.clone());
assert_eq!(canister_config(), Some(new_config));
}
Expand Down
2 changes: 1 addition & 1 deletion core/control-panel/impl/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub mod test_utils {
}

pub fn init_canister_config() {
let config = CanisterConfig::new(Vec::new(), Vec::new());
let config = CanisterConfig::new(Vec::new(), Vec::new(), None);
write_canister_config(config);
}
}
3 changes: 3 additions & 0 deletions core/control-panel/impl/src/services/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl CanisterService {
if let Some(station_wasm_module) = input.station_wasm_module {
config.station_wasm_module = station_wasm_module;
}
if let Some(station_wasm_module_extra_chunks) = input.station_wasm_module_extra_chunks {
config.station_wasm_module_extra_chunks = station_wasm_module_extra_chunks;
}
write_canister_config(config);

Ok(())
Expand Down
25 changes: 14 additions & 11 deletions core/control-panel/impl/src/services/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use ic_cdk::api::id as self_canister_id;
use ic_cdk::api::management_canister::main::{self as mgmt};
use lazy_static::lazy_static;
use orbit_essentials::api::ServiceResult;
use orbit_essentials::install_chunked_code::install_chunked_code;
use std::sync::Arc;

lazy_static! {
Expand Down Expand Up @@ -47,8 +48,9 @@ impl DeployService {
let config = canister_config().ok_or(DeployError::Failed {
reason: "Canister config not initialized.".to_string(),
})?;
let station_wasm_module = config.station_wasm_module;
let upgrader_wasm_module = config.upgrader_wasm_module;
let station_wasm_module = config.station_wasm_module;
let station_wasm_module_extra_chunks = config.station_wasm_module_extra_chunks;

let can_deploy_station_response = user.can_deploy_station();
match can_deploy_station_response {
Expand Down Expand Up @@ -97,11 +99,8 @@ impl DeployService {
.collect::<Vec<_>>();

// installs the station canister with the associated upgrader wasm module
mgmt::install_code(mgmt::InstallCodeArgument {
mode: mgmt::CanisterInstallMode::Install,
canister_id: station_canister.canister_id,
wasm_module: station_wasm_module,
arg: Encode!(&station_api::SystemInstall::Init(station_api::SystemInit {
let station_install_arg =
Encode!(&station_api::SystemInstall::Init(station_api::SystemInit {
name: input.name.clone(),
admins,
upgrader: station_api::SystemUpgraderInput::WasmModule(upgrader_wasm_module),
Expand All @@ -111,12 +110,16 @@ impl DeployService {
}))
.map_err(|err| DeployError::Failed {
reason: err.to_string(),
})?,
})
})?;
install_chunked_code(
station_canister.canister_id,
mgmt::CanisterInstallMode::Install,
station_wasm_module,
station_wasm_module_extra_chunks,
station_install_arg,
)
.await
.map_err(|(_, err)| DeployError::Failed {
reason: err.to_string(),
})?;
.map_err(|err| DeployError::Failed { reason: err })?;

self.user_service
.add_deployed_station(&user.id, station_canister.canister_id, ctx)
Expand Down
2 changes: 1 addition & 1 deletion libs/orbit-essentials/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use candid::{CandidType, Deserialize, Principal};
use serde::Serialize;

#[derive(CandidType, Deserialize, Serialize, Clone, Debug)]
#[derive(CandidType, Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
pub struct WasmModuleExtraChunks {
pub store_canister: Principal,
#[serde(deserialize_with = "crate::deserialize::deserialize_vec_blob")]
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/src/control_panel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,9 @@ fn upload_canister_modules_authorization() {
upload_canister_modules(&env, canister_ids.control_panel, controller);

let upload_canister_modules_args = UploadCanisterModulesInput {
station_wasm_module: None,
upgrader_wasm_module: None,
station_wasm_module: None,
station_wasm_module_extra_chunks: None,
};
let res: (ApiResult<()>,) = update_candid_as(
&env,
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ pub fn upload_canister_modules(env: &PocketIc, control_panel_id: Principal, cont
let upload_canister_modules_args = UploadCanisterModulesInput {
upgrader_wasm_module: Some(upgrader_wasm.to_owned()),
station_wasm_module: None,
station_wasm_module_extra_chunks: None,
};
let res: (ApiResult<()>,) = update_candid_as(
env,
Expand All @@ -727,10 +728,13 @@ pub fn upload_canister_modules(env: &PocketIc, control_panel_id: Principal, cont
res.0.unwrap();

// upload station
let station_wasm = get_canister_wasm("station").to_vec();
let station_wasm = get_canister_wasm("station");
let (base_chunk, module_extra_chunks) =
upload_canister_chunks_to_asset_canister(env, station_wasm, 200_000);
let upload_canister_modules_args = UploadCanisterModulesInput {
upgrader_wasm_module: None,
station_wasm_module: Some(station_wasm),
station_wasm_module: Some(base_chunk),
station_wasm_module_extra_chunks: Some(Some(module_extra_chunks)),
};
let res: (ApiResult<()>,) = update_candid_as(
env,
Expand Down
Loading