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
10 changes: 6 additions & 4 deletions crates/icp-cli/src/commands/canister/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ pub(crate) struct CanisterSettings {
#[arg(long)]
pub(crate) freezing_threshold: Option<u64>,

/// Optional reserved cycles limit. If set, the canister cannot consume more than this many cycles.
#[arg(long)]
pub(crate) reserved_cycles_limit: Option<u64>,
/// Optional upper limit on cycles reserved for future resource payments.
/// Memory allocations that would push the reserved balance above this limit will fail.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, value_parser = parse_cycles_amount)]
pub(crate) reserved_cycles_limit: Option<u128>,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -76,7 +78,7 @@ impl CreateArgs {
reserved_cycles_limit: self
.settings
.reserved_cycles_limit
.or(default.settings.reserved_cycles_limit)
.or(default.settings.reserved_cycles_limit.map(u128::from))
.map(Nat::from),
log_visibility: default.settings.log_visibility.clone().map(Into::into),
memory_allocation: self
Expand Down
3 changes: 2 additions & 1 deletion crates/icp-cli/src/commands/canister/settings/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ pub(crate) struct UpdateArgs {
#[arg(long, value_parser = freezing_threshold_parser)]
freezing_threshold: Option<u64>,

/// Reserved cycles limit for the canister.
/// Upper limit on cycles reserved for future resource payments.
/// Memory allocations that would push the reserved balance above this limit will fail.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, value_parser = parse_cycles_amount)]
reserved_cycles_limit: Option<u128>,
Expand Down
7 changes: 4 additions & 3 deletions crates/icp-cli/src/commands/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::Serialize;
use std::sync::Arc;

use crate::{
commands::canister::create,
commands::{canister::create, parsers::parse_cycles_amount},
operations::{
binding_env_vars::set_binding_env_vars_many,
build::build_many_with_progress_bar,
Expand Down Expand Up @@ -44,8 +44,9 @@ pub(crate) struct DeployArgs {
#[arg(long)]
pub(crate) controller: Vec<Principal>,

/// Cycles to fund canister creation (in cycles).
#[arg(long, default_value_t = create::DEFAULT_CANISTER_CYCLES)]
/// Cycles to fund canister creation.
/// Supports suffixes: k (thousand), m (million), b (billion), t (trillion).
#[arg(long, default_value_t = create::DEFAULT_CANISTER_CYCLES, value_parser = parse_cycles_amount)]
pub(crate) cycles: u128,

#[command(flatten)]
Expand Down
9 changes: 6 additions & 3 deletions crates/icp-cli/tests/canister_create_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async fn canister_create_with_settings() {
"--environment",
"random-environment",
"--cycles",
&format!("{}", 70 * TRILLION), /* 70T cycles because compute allocation is expensive */
"70t", /* 70T cycles because compute allocation is expensive */
])
.assert()
.success();
Expand Down Expand Up @@ -234,10 +234,12 @@ async fn canister_create_with_settings_cmdline_override() {
"my-canister",
"--compute-allocation",
"2",
"--reserved-cycles-limit",
"5t",
"--environment",
"random-environment",
"--cycles",
&format!("{}", 70 * TRILLION), /* 70T cycles because compute allocation is expensive */
"70t", /* 70T cycles because compute allocation is expensive */
])
.assert()
.success();
Expand All @@ -257,7 +259,8 @@ async fn canister_create_with_settings_cmdline_override() {
.stdout(
starts_with("Canister Id:")
.and(contains("Status: Running"))
.and(contains("Compute allocation: 2")),
.and(contains("Compute allocation: 2"))
.and(contains("Reserved cycles limit: 5_000_000_000_000")),
);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/icp-cli/tests/canister_settings_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ async fn canister_settings_update_miscellaneous() {
"--subnet",
common::SUBNET_ID,
"--cycles",
&format!("{}", 120 * TRILLION), // 120T cycles because compute allocation is expensive
"120t", // 120T cycles because compute allocation is expensive
"--environment",
"random-environment",
])
Expand Down Expand Up @@ -730,7 +730,7 @@ async fn canister_settings_update_miscellaneous() {
"--freezing-threshold",
"8640000",
"--reserved-cycles-limit",
"6000000000000",
"6t",
"--wasm-memory-limit",
"4GiB",
"--wasm-memory-threshold",
Expand Down
3 changes: 2 additions & 1 deletion crates/icp/src/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ pub struct Settings {
/// Freezing threshold in seconds. Controls how long a canister can be inactive before being frozen.
pub freezing_threshold: Option<u64>,

/// Reserved cycles limit. If set, the canister cannot consume more than this many cycles.
/// Upper limit on cycles reserved for future resource payments.
/// Memory allocations that would push the reserved balance above this limit will fail.
pub reserved_cycles_limit: Option<u64>,

/// Wasm memory limit in bytes. Sets an upper bound for Wasm heap growth.
Expand Down
16 changes: 8 additions & 8 deletions docs/reference/canister-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Time in seconds before the canister freezes due to low cycles.
|----------|-------|
| Type | Integer |
| Unit | Seconds |
| Default | 2592000 (30 days) |
| Default | 2,592,000 (30 days) |

```yaml
settings:
Expand All @@ -62,13 +62,13 @@ The canister freezes if its cycles balance would be exhausted within this thresh

### reserved_cycles_limit

Maximum cycles the canister can hold in reserve.
Upper limit on cycles reserved for future resource payments. When a canister allocates new storage on a subnet above 750 GiB usage, cycles are moved from its main balance into a reserved balance to pre-pay for future storage costs. This setting caps that reserved balance — memory allocations that would push it above the limit will fail. Set to `0` to disable resource reservation entirely (prevents memory allocation on subnets above 750 GiB).

| Property | Value |
|----------|-------|
| Type | Integer |
| Unit | Cycles |
| Default | No limit |
| IC Default | 5,000,000,000,000 (5T) |

```yaml
settings:
Expand Down Expand Up @@ -164,11 +164,11 @@ canisters:
- cp target/wasm32-unknown-unknown/release/backend.wasm "$ICP_WASM_OUTPUT_PATH"
settings:
compute_allocation: 5
memory_allocation: 2147483648 # 2GB
freezing_threshold: 2592000 # 30 days
reserved_cycles_limit: 5000000000000
wasm_memory_limit: 1073741824 # 1GB
wasm_memory_threshold: 536870912 # 512MB
memory_allocation: 2147483648 # 2GB
freezing_threshold: 2592000 # 30 days
reserved_cycles_limit: 5000000000000 # 5T cycles
wasm_memory_limit: 1073741824 # 1GB
wasm_memory_threshold: 536870912 # 512MB
log_visibility: controllers
environment_variables:
ENV: "production"
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Create a canister on a network
* `--compute-allocation <COMPUTE_ALLOCATION>` — Optional compute allocation (0 to 100). Represents guaranteed compute capacity
* `--memory-allocation <MEMORY_ALLOCATION>` — Optional memory allocation in bytes. If unset, memory is allocated dynamically
* `--freezing-threshold <FREEZING_THRESHOLD>` — Optional freezing threshold in seconds. Controls how long a canister can be inactive before being frozen
* `--reserved-cycles-limit <RESERVED_CYCLES_LIMIT>` — Optional reserved cycles limit. If set, the canister cannot consume more than this many cycles
* `--reserved-cycles-limit <RESERVED_CYCLES_LIMIT>` — Optional upper limit on cycles reserved for future resource payments. Memory allocations that would push the reserved balance above this limit will fail. Supports suffixes: k (thousand), m (million), b (billion), t (trillion)
* `-q`, `--quiet` — Suppress human-readable output; print only canister IDs, one per line, to stdout
* `--cycles <CYCLES>` — Cycles to fund canister creation. Supports suffixes: k (thousand), m (million), b (billion), t (trillion)

Expand Down Expand Up @@ -364,7 +364,7 @@ Change a canister's settings to specified values
* `--compute-allocation <COMPUTE_ALLOCATION>`
* `--memory-allocation <MEMORY_ALLOCATION>`
* `--freezing-threshold <FREEZING_THRESHOLD>`
* `--reserved-cycles-limit <RESERVED_CYCLES_LIMIT>` — Reserved cycles limit for the canister. Supports suffixes: k (thousand), m (million), b (billion), t (trillion)
* `--reserved-cycles-limit <RESERVED_CYCLES_LIMIT>` — Upper limit on cycles reserved for future resource payments. Memory allocations that would push the reserved balance above this limit will fail. Supports suffixes: k (thousand), m (million), b (billion), t (trillion)
* `--wasm-memory-limit <WASM_MEMORY_LIMIT>`
* `--wasm-memory-threshold <WASM_MEMORY_THRESHOLD>`
* `--log-visibility <LOG_VISIBILITY>`
Expand Down Expand Up @@ -689,7 +689,7 @@ Deploy a project to an environment

* `--subnet <SUBNET>` — The subnet to use for the canisters being deployed
* `--controller <CONTROLLER>` — One or more controllers for the canisters being deployed. Repeat `--controller` to specify multiple
* `--cycles <CYCLES>` — Cycles to fund canister creation (in cycles)
* `--cycles <CYCLES>` — Cycles to fund canister creation. Supports suffixes: k (thousand), m (million), b (billion), t (trillion)

Default value: `2000000000000`
* `--identity <IDENTITY>` — The user identity to run this command as
Expand Down
2 changes: 1 addition & 1 deletion docs/schemas/canister-yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
]
},
"reserved_cycles_limit": {
"description": "Reserved cycles limit. If set, the canister cannot consume more than this many cycles.",
"description": "Upper limit on cycles reserved for future resource payments.\nMemory allocations that would push the reserved balance above this limit will fail.",
"format": "uint64",
"minimum": 0,
"type": [
Expand Down
2 changes: 1 addition & 1 deletion docs/schemas/environment-yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
]
},
"reserved_cycles_limit": {
"description": "Reserved cycles limit. If set, the canister cannot consume more than this many cycles.",
"description": "Upper limit on cycles reserved for future resource payments.\nMemory allocations that would push the reserved balance above this limit will fail.",
"format": "uint64",
"minimum": 0,
"type": [
Expand Down
2 changes: 1 addition & 1 deletion docs/schemas/icp-yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@
]
},
"reserved_cycles_limit": {
"description": "Reserved cycles limit. If set, the canister cannot consume more than this many cycles.",
"description": "Upper limit on cycles reserved for future resource payments.\nMemory allocations that would push the reserved balance above this limit will fail.",
"format": "uint64",
"minimum": 0,
"type": [
Expand Down
Loading