Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/agent/rust/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion src/agent/rust/src/agent/replica_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub enum SubmitRequest<'a> {
module: &'a Blob,
arg: &'a Blob,
nonce: &'a Option<Blob>,
compute_allocation: u8,
#[serde(skip_serializing_if = "Option::is_none")]
compute_allocation: Option<u8>,
},
Call {
canister_id: &'a CanisterId,
Expand Down
4 changes: 2 additions & 2 deletions src/agent/rust/src/types/canister_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ impl std::convert::TryFrom<u8> for ComputeAllocation {
}

pub struct CanisterAttributes {
pub compute_allocation: ComputeAllocation,
pub compute_allocation: Option<ComputeAllocation>,
}

impl Default for CanisterAttributes {
fn default() -> Self {
CanisterAttributes {
compute_allocation: ComputeAllocation(0),
compute_allocation: None,
}
}
}
16 changes: 6 additions & 10 deletions src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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),
)
}
Expand All @@ -48,7 +47,7 @@ async fn install_canister(
env: &dyn Environment,
agent: &Agent,
canister_info: &CanisterInfo,
compute_allocation: ComputeAllocation,
compute_allocation: Option<ComputeAllocation>,
) -> DfxResult<RequestId> {
let log = env.get_logger();
let canister_id = canister_info.get_canister_id().ok_or_else(|| {
Expand Down Expand Up @@ -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::<u64>()
.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::<u64>().unwrap())
.expect("Compute Allocation must be a percentage.")
});

let mut runtime = Runtime::new().expect("Unable to create a runtime");

Expand Down