diff --git a/src/agent/rust/src/agent/mod.rs b/src/agent/rust/src/agent/mod.rs index 20c1bf0acc..80691ba7b8 100644 --- a/src/agent/rust/src/agent/mod.rs +++ b/src/agent/rust/src/agent/mod.rs @@ -221,7 +221,7 @@ impl Agent { module, arg, nonce: &self.nonce_factory.generate(), - compute_allocation: attributes.compute_allocation.0, + compute_allocation: attributes.compute_allocation.map(|x| x.into()), }) .await } diff --git a/src/agent/rust/src/agent/replica_api.rs b/src/agent/rust/src/agent/replica_api.rs index 01e81d3870..5ace9449eb 100644 --- a/src/agent/rust/src/agent/replica_api.rs +++ b/src/agent/rust/src/agent/replica_api.rs @@ -47,7 +47,8 @@ pub enum SubmitRequest<'a> { module: &'a Blob, arg: &'a Blob, nonce: &'a Option, - compute_allocation: u8, + #[serde(skip_serializing_if = "Option::is_none")] + compute_allocation: Option, }, Call { canister_id: &'a CanisterId, diff --git a/src/agent/rust/src/types/canister_attributes.rs b/src/agent/rust/src/types/canister_attributes.rs index eccc62cf16..5ee1fbe3d0 100644 --- a/src/agent/rust/src/types/canister_attributes.rs +++ b/src/agent/rust/src/types/canister_attributes.rs @@ -47,13 +47,13 @@ impl std::convert::TryFrom for ComputeAllocation { } pub struct CanisterAttributes { - pub compute_allocation: ComputeAllocation, + pub compute_allocation: Option, } impl Default for CanisterAttributes { fn default() -> Self { CanisterAttributes { - compute_allocation: ComputeAllocation(0), + compute_allocation: None, } } } diff --git a/src/dfx/src/commands/canister/install.rs b/src/dfx/src/commands/canister/install.rs index 3e7b55e110..daea360e20 100644 --- a/src/dfx/src/commands/canister/install.rs +++ b/src/dfx/src/commands/canister/install.rs @@ -7,7 +7,7 @@ use crate::lib::message::UserMessage; use clap::{App, Arg, ArgMatches, SubCommand}; use ic_agent::{Agent, Blob, CanisterAttributes, ComputeAllocation, RequestId}; use slog::info; -use std::convert::TryInto; +use std::convert::TryFrom; use tokio::runtime::Runtime; pub fn construct() -> App<'static, 'static> { @@ -39,7 +39,6 @@ pub fn construct() -> App<'static, 'static> { .long("compute-allocation") .short("c") .takes_value(true) - .default_value("0") .validator(compute_allocation_validator), ) } @@ -48,7 +47,7 @@ async fn install_canister( env: &dyn Environment, agent: &Agent, canister_info: &CanisterInfo, - compute_allocation: ComputeAllocation, + compute_allocation: Option, ) -> DfxResult { let log = env.get_logger(); let canister_id = canister_info.get_canister_id().ok_or_else(|| { @@ -93,13 +92,10 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { let agent = env .get_agent() .ok_or(DfxError::CommandMustBeRunInAProject)?; - let compute_allocation: ComputeAllocation = args - .value_of("compute-allocation") - .unwrap_or("0") - .parse::() - .unwrap() - .try_into() - .expect("Compute Allocation must be a percentage."); + let compute_allocation = args.value_of("compute-allocation").map(|arg| { + ComputeAllocation::try_from(arg.parse::().unwrap()) + .expect("Compute Allocation must be a percentage.") + }); let mut runtime = Runtime::new().expect("Unable to create a runtime");