From 86325cfbdf13a4b223faca85f951d454d50acc23 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:01:24 -0800 Subject: [PATCH 01/11] fix: update-settings --all now skips remote canisters --- e2e/tests-dfx/update_settings.bash | 19 +++++++++++++++++++ .../src/commands/canister/update_settings.rs | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/e2e/tests-dfx/update_settings.bash b/e2e/tests-dfx/update_settings.bash index 74d668cf61..ea22cad3ab 100644 --- a/e2e/tests-dfx/update_settings.bash +++ b/e2e/tests-dfx/update_settings.bash @@ -14,6 +14,25 @@ teardown() { standard_teardown } +@test "the --all option excludes remote canisters" { + dfx_new + dfx_start + assert_command dfx deploy e2e_project_backend + assert_command dfx canister status e2e_project_backend + + jq '.canisters.internet_identity.remote.id.local = "rdmx6-jaaaa-aaaaa-aaadq-cai"' dfx.json | sponge dfx.json + + # Test --all code path. + assert_command dfx canister update-settings --log-visibility public --all + assert_contains "Skipping canister 'internet_identity' because it is remote for network 'local'" + assert_command dfx canister status e2e_project_backend + assert_contains "Log visibility: public" + assert_command dfx canister update-settings --log-visibility controllers --all + assert_command dfx canister status e2e_project_backend + assert_contains "Log visibility: controllers" + +} + @test "set reserved cycles limit" { dfx_start assert_command dfx deploy hello_backend diff --git a/src/dfx/src/commands/canister/update_settings.rs b/src/dfx/src/commands/canister/update_settings.rs index f6867c58af..48407fb977 100644 --- a/src/dfx/src/commands/canister/update_settings.rs +++ b/src/dfx/src/commands/canister/update_settings.rs @@ -22,6 +22,7 @@ use dfx_core::identity::CallSender; use fn_error_context::context; use ic_agent::identity::Identity; use ic_utils::interfaces::management_canister::StatusCallResult; +use slog::info; /// Update one or more of a canister's settings (i.e its controller, compute allocation, or memory allocation.) #[derive(Parser, Debug)] @@ -220,8 +221,20 @@ pub async fn exec( // Update all canister settings. let config = env.get_config_or_anyhow()?; let config_interface = config.get_config(); + let network = env.get_network_descriptor(); if let Some(canisters) = &config_interface.canisters { for canister_name in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister_name, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister_name}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } let mut controllers = controllers.clone(); let canister_id = canister_id_store.get(canister_name)?; let compute_allocation = get_compute_allocation( From 48dd5488fd748900bb1ae3de9ad0658905270bd8 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:09:58 -0800 Subject: [PATCH 02/11] canister stop --- e2e/tests-dfx/remote.bash | 3 +++ src/dfx/src/commands/canister/stop.rs | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index 390070157e..fb97d179c3 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -201,6 +201,9 @@ teardown() { assert_command jq .remote canister_ids.json assert_eq "null" + assert_command dfx canister stop --all --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + # Assert frontend declarations are actually created dfx generate assert_file_exists "src/declarations/remote/remote.did" diff --git a/src/dfx/src/commands/canister/stop.rs b/src/dfx/src/commands/canister/stop.rs index 7f71472908..bcb067e6dc 100644 --- a/src/dfx/src/commands/canister/stop.rs +++ b/src/dfx/src/commands/canister/stop.rs @@ -52,8 +52,22 @@ pub async fn exec( stop_canister(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - if let Some(canisters) = &config.get_config().canisters { + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } + stop_canister(env, canister, call_sender).await?; } } From 3a877d0cd0b45c8387bcd7224d58e74eeb3b66dd Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:16:23 -0800 Subject: [PATCH 03/11] canister uninstall-code --- e2e/tests-dfx/remote.bash | 3 +++ src/dfx/src/commands/canister/uninstall_code.rs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index fb97d179c3..49cf1dfea8 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -204,6 +204,9 @@ teardown() { assert_command dfx canister stop --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + assert_command dfx canister uninstall-code --all --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + # Assert frontend declarations are actually created dfx generate assert_file_exists "src/declarations/remote/remote.did" diff --git a/src/dfx/src/commands/canister/uninstall_code.rs b/src/dfx/src/commands/canister/uninstall_code.rs index 4b386d7a36..170d5f067b 100644 --- a/src/dfx/src/commands/canister/uninstall_code.rs +++ b/src/dfx/src/commands/canister/uninstall_code.rs @@ -53,9 +53,22 @@ pub async fn exec( uninstall_code(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); - if let Some(canisters) = &config.get_config().canisters { + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } uninstall_code(env, canister, call_sender).await?; } } From 80d6c1519cd160b9acbc52cf0c00ccffec8df74c Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:21:19 -0800 Subject: [PATCH 04/11] move update-settings test --- e2e/tests-dfx/remote.bash | 3 +++ e2e/tests-dfx/update_settings.bash | 19 ------------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index 49cf1dfea8..4eae8474cb 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -201,6 +201,9 @@ teardown() { assert_command jq .remote canister_ids.json assert_eq "null" + assert_command dfx canister update-settings --log-visibility public --all --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + assert_command dfx canister stop --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" diff --git a/e2e/tests-dfx/update_settings.bash b/e2e/tests-dfx/update_settings.bash index ea22cad3ab..74d668cf61 100644 --- a/e2e/tests-dfx/update_settings.bash +++ b/e2e/tests-dfx/update_settings.bash @@ -14,25 +14,6 @@ teardown() { standard_teardown } -@test "the --all option excludes remote canisters" { - dfx_new - dfx_start - assert_command dfx deploy e2e_project_backend - assert_command dfx canister status e2e_project_backend - - jq '.canisters.internet_identity.remote.id.local = "rdmx6-jaaaa-aaaaa-aaadq-cai"' dfx.json | sponge dfx.json - - # Test --all code path. - assert_command dfx canister update-settings --log-visibility public --all - assert_contains "Skipping canister 'internet_identity' because it is remote for network 'local'" - assert_command dfx canister status e2e_project_backend - assert_contains "Log visibility: public" - assert_command dfx canister update-settings --log-visibility controllers --all - assert_command dfx canister status e2e_project_backend - assert_contains "Log visibility: controllers" - -} - @test "set reserved cycles limit" { dfx_start assert_command dfx deploy hello_backend From c01ad2cb27687ffa2e40cc938a7e30df6b3a4e4f Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:27:06 -0800 Subject: [PATCH 05/11] canister delete --- e2e/tests-dfx/remote.bash | 7 ++++++- src/dfx/src/commands/canister/delete.rs | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index 4eae8474cb..b0fd7f48ec 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -137,7 +137,7 @@ teardown() { assert_match "Canister 'remote' is a remote canister on network 'actuallylocal', and cannot be installed from here." } -@test "canister create --all, canister install --all skip remote canisters" { +@test "all commands with --all skip remote canisters" { install_asset remote/actual dfx_start setup_actuallylocal_shared_network @@ -210,6 +210,11 @@ teardown() { assert_command dfx canister uninstall-code --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + assert_command dfx build --all --network actuallylocal + + assert_command dfx canister delete --all --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + # Assert frontend declarations are actually created dfx generate assert_file_exists "src/declarations/remote/remote.did" diff --git a/src/dfx/src/commands/canister/delete.rs b/src/dfx/src/commands/canister/delete.rs index 74a2c66748..2d53e2b519 100644 --- a/src/dfx/src/commands/canister/delete.rs +++ b/src/dfx/src/commands/canister/delete.rs @@ -350,8 +350,21 @@ pub async fn exec( ) .await } else if opts.all { - if let Some(canisters) = &config.get_config().canisters { + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } delete_canister( env, canister, From 092e491680c401e04487300cc19f3cb617b80cc1 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:32:35 -0800 Subject: [PATCH 06/11] canister status --- e2e/tests-dfx/remote.bash | 3 +++ src/dfx/src/commands/canister/status.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index b0fd7f48ec..c0265433a0 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -201,6 +201,9 @@ teardown() { assert_command jq .remote canister_ids.json assert_eq "null" + assert_command dfx canister status --all --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + assert_command dfx canister update-settings --log-visibility public --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" diff --git a/src/dfx/src/commands/canister/status.rs b/src/dfx/src/commands/canister/status.rs index d3183759b9..6577c55f08 100644 --- a/src/dfx/src/commands/canister/status.rs +++ b/src/dfx/src/commands/canister/status.rs @@ -7,6 +7,7 @@ use clap::Parser; use dfx_core::identity::CallSender; use fn_error_context::context; use ic_utils::interfaces::management_canister::LogVisibility; +use slog::info; /// Returns the current status of a canister: Running, Stopping, or Stopped. Also carries information like balance, current settings, memory used and everything returned by 'info'. #[derive(Parser)] @@ -95,8 +96,22 @@ pub async fn exec( canister_status(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - if let Some(canisters) = &config.get_config().canisters { + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } + canister_status(env, canister, call_sender).await?; } } From 51c8b96b327d7c0ce94c367434ab750afcc5e376 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 25 Nov 2024 23:52:58 -0800 Subject: [PATCH 07/11] canister deposit-cycles --- e2e/tests-dfx/cycles-ledger.bash | 7 +++++++ src/dfx/src/commands/canister/deposit_cycles.rs | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/cycles-ledger.bash b/e2e/tests-dfx/cycles-ledger.bash index 7c20cbf057..3a279b6c0b 100644 --- a/e2e/tests-dfx/cycles-ledger.bash +++ b/e2e/tests-dfx/cycles-ledger.bash @@ -458,6 +458,13 @@ current_time_nanoseconds() { assert_eq "2399699700000 cycles." assert_command dfx canister status e2e_project_backend assert_contains "Balance: 3_100_002_100_000 Cycles" + + # deposit-cycles --all skips remote canisters + jq '.canisters.remote.remote.id.local="rdmx6-jaaaa-aaaaa-aaadq-cai"' dfx.json | sponge dfx.json + assert_command dfx canister deposit-cycles 10000 --all --identity bob + assert_contains "Skipping canister 'remote' because it is remote for network 'local'" + assert_contains "Depositing 10000 cycles onto e2e_project_backend" + assert_not_contains "Depositing 10000 cycles onto remote" } @test "top-up deduplication" { diff --git a/src/dfx/src/commands/canister/deposit_cycles.rs b/src/dfx/src/commands/canister/deposit_cycles.rs index 1db8196e38..fe2c48b1f7 100644 --- a/src/dfx/src/commands/canister/deposit_cycles.rs +++ b/src/dfx/src/commands/canister/deposit_cycles.rs @@ -144,9 +144,23 @@ pub async fn exec( .await } else if opts.all { let config = env.get_config_or_anyhow()?; + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); - if let Some(canisters) = &config.get_config().canisters { + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } + deposit_cycles( env, canister, From a8581799e7fa4feeb635349c004b753af38a0efd Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Tue, 26 Nov 2024 00:11:33 -0800 Subject: [PATCH 08/11] canister start --- e2e/tests-dfx/remote.bash | 6 ++++++ src/dfx/src/commands/canister/start.rs | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index c0265433a0..423547fd13 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -210,6 +210,12 @@ teardown() { assert_command dfx canister stop --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + assert_command dfx canister start --all --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + + # have to stop to uninstall + assert_command dfx canister stop --all --network actuallylocal + assert_command dfx canister uninstall-code --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" diff --git a/src/dfx/src/commands/canister/start.rs b/src/dfx/src/commands/canister/start.rs index 529817ca59..2c8c2907a9 100644 --- a/src/dfx/src/commands/canister/start.rs +++ b/src/dfx/src/commands/canister/start.rs @@ -51,8 +51,22 @@ pub async fn exec( start_canister(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - if let Some(canisters) = &config.get_config().canisters { + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } + start_canister(env, canister, call_sender).await?; } } From 7e84023734d56a98fba1d03f33980f9cc0dd6005 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Tue, 26 Nov 2024 00:17:49 -0800 Subject: [PATCH 09/11] ledger fabricate-cycles --- e2e/tests-dfx/remote.bash | 3 +++ src/dfx/src/commands/ledger/fabricate_cycles.rs | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index 423547fd13..8e8bc5568e 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -201,6 +201,9 @@ teardown() { assert_command jq .remote canister_ids.json assert_eq "null" + assert_command dfx ledger fabricate-cycles --all --t 100 --network actuallylocal + assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" + assert_command dfx canister status --all --network actuallylocal assert_contains "Skipping canister 'remote' because it is remote for network 'actuallylocal'" diff --git a/src/dfx/src/commands/ledger/fabricate_cycles.rs b/src/dfx/src/commands/ledger/fabricate_cycles.rs index 447bc9b405..199cd41a69 100644 --- a/src/dfx/src/commands/ledger/fabricate_cycles.rs +++ b/src/dfx/src/commands/ledger/fabricate_cycles.rs @@ -120,8 +120,22 @@ pub async fn exec(env: &dyn Environment, opts: FabricateCyclesOpts) -> DfxResult deposit_minted_cycles(env, canister, &CallSender::SelectedId, cycles).await } else if opts.all { let config = env.get_config_or_anyhow()?; - if let Some(canisters) = &config.get_config().canisters { + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); + if let Some(canisters) = &config_interface.canisters { for canister in canisters.keys() { + let canister_is_remote = + config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", + &network.name, + ); + + continue; + } + deposit_minted_cycles(env, canister, &CallSender::SelectedId, cycles).await?; } } From 63127cf2c66d9a044ec6f211b624c3cd4d337039 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Tue, 26 Nov 2024 00:32:26 -0800 Subject: [PATCH 10/11] dry --- src/dfx/src/commands/canister/create.rs | 12 ++---------- src/dfx/src/commands/canister/delete.rs | 16 +++------------- src/dfx/src/commands/canister/deposit_cycles.rs | 15 +++------------ src/dfx/src/commands/canister/install.rs | 10 ++-------- src/dfx/src/commands/canister/start.rs | 16 ++++------------ src/dfx/src/commands/canister/status.rs | 17 ++++------------- src/dfx/src/commands/canister/stop.rs | 16 ++++------------ src/dfx/src/commands/canister/uninstall_code.rs | 15 +++------------ .../src/commands/canister/update_settings.rs | 17 +++++------------ src/dfx/src/commands/ledger/fabricate_cycles.rs | 16 ++++------------ src/dfx/src/lib/operations/canister/mod.rs | 2 ++ .../operations/canister/skip_remote_canister.rs | 17 +++++++++++++++++ 12 files changed, 53 insertions(+), 116 deletions(-) create mode 100644 src/dfx/src/lib/operations/canister/skip_remote_canister.rs diff --git a/src/dfx/src/commands/canister/create.rs b/src/dfx/src/commands/canister/create.rs index a5293f0f1c..368ee604f5 100644 --- a/src/dfx/src/commands/canister/create.rs +++ b/src/dfx/src/commands/canister/create.rs @@ -6,7 +6,7 @@ use crate::lib::ic_attributes::{ get_compute_allocation, get_freezing_threshold, get_log_visibility, get_memory_allocation, get_reserved_cycles_limit, get_wasm_memory_limit, CanisterSettings, }; -use crate::lib::operations::canister::create_canister; +use crate::lib::operations::canister::{create_canister, skip_remote_canister}; use crate::lib::root_key::fetch_root_key_if_needed; use crate::util::clap::parsers::{ compute_allocation_parser, freezing_threshold_parser, log_visibility_parser, @@ -245,15 +245,7 @@ pub async fn exec( if pull_canisters_in_config.contains_key(canister_name) { continue; } - let canister_is_remote = - config_interface.is_remote_canister(canister_name, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister_name}' because it is remote for network '{}'", - &network.name, - ); - + if skip_remote_canister(env, canister_name)? { continue; } let specified_id = config_interface.get_specified_id(canister_name)?; diff --git a/src/dfx/src/commands/canister/delete.rs b/src/dfx/src/commands/canister/delete.rs index 2d53e2b519..02d3dcb30f 100644 --- a/src/dfx/src/commands/canister/delete.rs +++ b/src/dfx/src/commands/canister/delete.rs @@ -3,7 +3,7 @@ use crate::lib::error::DfxResult; use crate::lib::ic_attributes::CanisterSettings; use crate::lib::operations::canister; use crate::lib::operations::canister::{ - deposit_cycles, start_canister, stop_canister, update_settings, + deposit_cycles, skip_remote_canister, start_canister, stop_canister, update_settings, }; use crate::lib::operations::cycles_ledger::wallet_deposit_to_cycles_ledger; use crate::lib::root_key::fetch_root_key_if_needed; @@ -350,19 +350,9 @@ pub async fn exec( ) .await } else if opts.all { - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { + if let Some(canisters) = &config.get_config().canisters { for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); - + if skip_remote_canister(env, canister)? { continue; } delete_canister( diff --git a/src/dfx/src/commands/canister/deposit_cycles.rs b/src/dfx/src/commands/canister/deposit_cycles.rs index fe2c48b1f7..3a2bb26e0c 100644 --- a/src/dfx/src/commands/canister/deposit_cycles.rs +++ b/src/dfx/src/commands/canister/deposit_cycles.rs @@ -3,6 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use crate::lib::error::DfxResult; use crate::lib::identity::wallet::get_or_create_wallet_canister; use crate::lib::operations::canister; +use crate::lib::operations::canister::skip_remote_canister; use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::{environment::Environment, operations::cycles_ledger}; use crate::util::clap::parsers::{cycle_amount_parser, icrc_subaccount_parser}; @@ -144,20 +145,10 @@ pub async fn exec( .await } else if opts.all { let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { + if let Some(canisters) = &config.get_config().canisters { for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); - + if skip_remote_canister(env, canister)? { continue; } diff --git a/src/dfx/src/commands/canister/install.rs b/src/dfx/src/commands/canister/install.rs index d992ca2d9e..bb8e1de50b 100644 --- a/src/dfx/src/commands/canister/install.rs +++ b/src/dfx/src/commands/canister/install.rs @@ -10,6 +10,7 @@ use crate::util::clap::install_mode::{InstallModeHint, InstallModeOpt}; use dfx_core::canister::{install_canister_wasm, install_mode_to_prompt}; use dfx_core::identity::CallSender; +use crate::lib::operations::canister::skip_remote_canister; use anyhow::bail; use candid::Principal; use clap::Parser; @@ -187,7 +188,6 @@ pub async fn exec( } else if opts.all { // Install all canisters. let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); let env_file = config.get_output_env_file(opts.output_env_file)?; let pull_canisters_in_config = get_pull_canisters_in_config(env)?; if let Some(canisters) = &config.get_config().canisters { @@ -195,13 +195,7 @@ pub async fn exec( if pull_canisters_in_config.contains_key(canister) { continue; } - if config_interface.is_remote_canister(canister, &network.name)? { - info!( - env.get_logger(), - "Skipping canister '{}' because it is remote for network '{}'", - canister, - &network.name, - ); + if skip_remote_canister(env, canister)? { continue; } diff --git a/src/dfx/src/commands/canister/start.rs b/src/dfx/src/commands/canister/start.rs index 2c8c2907a9..e3ff066710 100644 --- a/src/dfx/src/commands/canister/start.rs +++ b/src/dfx/src/commands/canister/start.rs @@ -1,6 +1,7 @@ use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::operations::canister; +use crate::lib::operations::canister::skip_remote_canister; use crate::lib::root_key::fetch_root_key_if_needed; use candid::Principal; use clap::Parser; @@ -51,19 +52,10 @@ pub async fn exec( start_canister(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { - for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); + if let Some(canisters) = &config.get_config().canisters { + for canister in canisters.keys() { + if skip_remote_canister(env, canister)? { continue; } diff --git a/src/dfx/src/commands/canister/status.rs b/src/dfx/src/commands/canister/status.rs index 6577c55f08..ecd8d7773d 100644 --- a/src/dfx/src/commands/canister/status.rs +++ b/src/dfx/src/commands/canister/status.rs @@ -1,13 +1,13 @@ use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::operations::canister; +use crate::lib::operations::canister::skip_remote_canister; use crate::lib::root_key::fetch_root_key_if_needed; use candid::Principal; use clap::Parser; use dfx_core::identity::CallSender; use fn_error_context::context; use ic_utils::interfaces::management_canister::LogVisibility; -use slog::info; /// Returns the current status of a canister: Running, Stopping, or Stopped. Also carries information like balance, current settings, memory used and everything returned by 'info'. #[derive(Parser)] @@ -96,19 +96,10 @@ pub async fn exec( canister_status(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { - for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); + if let Some(canisters) = &config.get_config().canisters { + for canister in canisters.keys() { + if skip_remote_canister(env, canister)? { continue; } diff --git a/src/dfx/src/commands/canister/stop.rs b/src/dfx/src/commands/canister/stop.rs index bcb067e6dc..4e44a539a8 100644 --- a/src/dfx/src/commands/canister/stop.rs +++ b/src/dfx/src/commands/canister/stop.rs @@ -1,6 +1,7 @@ use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::operations::canister; +use crate::lib::operations::canister::skip_remote_canister; use crate::lib::root_key::fetch_root_key_if_needed; use candid::Principal; use clap::Parser; @@ -52,19 +53,10 @@ pub async fn exec( stop_canister(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { - for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); + if let Some(canisters) = &config.get_config().canisters { + for canister in canisters.keys() { + if skip_remote_canister(env, canister)? { continue; } diff --git a/src/dfx/src/commands/canister/uninstall_code.rs b/src/dfx/src/commands/canister/uninstall_code.rs index 170d5f067b..602e3182e7 100644 --- a/src/dfx/src/commands/canister/uninstall_code.rs +++ b/src/dfx/src/commands/canister/uninstall_code.rs @@ -1,6 +1,7 @@ use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::operations::canister; +use crate::lib::operations::canister::skip_remote_canister; use crate::lib::root_key::fetch_root_key_if_needed; use candid::Principal; use clap::Parser; @@ -53,20 +54,10 @@ pub async fn exec( uninstall_code(env, canister, call_sender).await } else if opts.all { let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { + if let Some(canisters) = &config.get_config().canisters { for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); - + if skip_remote_canister(env, canister)? { continue; } uninstall_code(env, canister, call_sender).await?; diff --git a/src/dfx/src/commands/canister/update_settings.rs b/src/dfx/src/commands/canister/update_settings.rs index 48407fb977..db3a3184eb 100644 --- a/src/dfx/src/commands/canister/update_settings.rs +++ b/src/dfx/src/commands/canister/update_settings.rs @@ -6,7 +6,9 @@ use crate::lib::ic_attributes::{ get_compute_allocation, get_freezing_threshold, get_log_visibility, get_memory_allocation, get_reserved_cycles_limit, get_wasm_memory_limit, CanisterSettings, }; -use crate::lib::operations::canister::{get_canister_status, update_settings}; +use crate::lib::operations::canister::{ + get_canister_status, skip_remote_canister, update_settings, +}; use crate::lib::root_key::fetch_root_key_if_needed; use crate::util::clap::parsers::{ compute_allocation_parser, freezing_threshold_parser, memory_allocation_parser, @@ -22,7 +24,6 @@ use dfx_core::identity::CallSender; use fn_error_context::context; use ic_agent::identity::Identity; use ic_utils::interfaces::management_canister::StatusCallResult; -use slog::info; /// Update one or more of a canister's settings (i.e its controller, compute allocation, or memory allocation.) #[derive(Parser, Debug)] @@ -221,18 +222,10 @@ pub async fn exec( // Update all canister settings. let config = env.get_config_or_anyhow()?; let config_interface = config.get_config(); - let network = env.get_network_descriptor(); + if let Some(canisters) = &config_interface.canisters { for canister_name in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister_name, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister_name}' because it is remote for network '{}'", - &network.name, - ); - + if skip_remote_canister(env, canister_name)? { continue; } let mut controllers = controllers.clone(); diff --git a/src/dfx/src/commands/ledger/fabricate_cycles.rs b/src/dfx/src/commands/ledger/fabricate_cycles.rs index 199cd41a69..ef0f239efa 100644 --- a/src/dfx/src/commands/ledger/fabricate_cycles.rs +++ b/src/dfx/src/commands/ledger/fabricate_cycles.rs @@ -3,6 +3,7 @@ use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::nns_types::icpts::ICPTs; use crate::lib::operations::canister; +use crate::lib::operations::canister::skip_remote_canister; use crate::lib::root_key::fetch_root_key_or_anyhow; use crate::util::clap::parsers::{cycle_amount_parser, e8s_parser, trillion_cycle_amount_parser}; use crate::util::currency_conversion::as_cycles_with_current_exchange_rate; @@ -120,19 +121,10 @@ pub async fn exec(env: &dyn Environment, opts: FabricateCyclesOpts) -> DfxResult deposit_minted_cycles(env, canister, &CallSender::SelectedId, cycles).await } else if opts.all { let config = env.get_config_or_anyhow()?; - let config_interface = config.get_config(); - let network = env.get_network_descriptor(); - if let Some(canisters) = &config_interface.canisters { - for canister in canisters.keys() { - let canister_is_remote = - config_interface.is_remote_canister(canister, &network.name)?; - if canister_is_remote { - info!( - env.get_logger(), - "Skipping canister '{canister}' because it is remote for network '{}'", - &network.name, - ); + if let Some(canisters) = &config.get_config().canisters { + for canister in canisters.keys() { + if skip_remote_canister(env, canister)? { continue; } diff --git a/src/dfx/src/lib/operations/canister/mod.rs b/src/dfx/src/lib/operations/canister/mod.rs index 501dc9284d..9551ddc4fb 100644 --- a/src/dfx/src/lib/operations/canister/mod.rs +++ b/src/dfx/src/lib/operations/canister/mod.rs @@ -2,10 +2,12 @@ pub(crate) mod create_canister; pub(crate) mod deploy_canisters; pub(crate) mod install_canister; pub mod motoko_playground; +mod skip_remote_canister; pub use create_canister::create_canister; use ic_utils::interfaces::management_canister::Snapshot; pub use install_canister::install_wallet; +pub use skip_remote_canister::skip_remote_canister; use crate::lib::canister_info::CanisterInfo; use crate::lib::environment::Environment; diff --git a/src/dfx/src/lib/operations/canister/skip_remote_canister.rs b/src/dfx/src/lib/operations/canister/skip_remote_canister.rs new file mode 100644 index 0000000000..6ce603cf1a --- /dev/null +++ b/src/dfx/src/lib/operations/canister/skip_remote_canister.rs @@ -0,0 +1,17 @@ +use crate::lib::environment::Environment; +use crate::lib::error::DfxResult; +use slog::info; + +pub fn skip_remote_canister(env: &dyn Environment, canister: &str) -> DfxResult { + let config = env.get_config_or_anyhow()?; + let config_interface = config.get_config(); + let network = env.get_network_descriptor(); + let canister_is_remote = config_interface.is_remote_canister(canister, &network.name)?; + if canister_is_remote { + info!( + env.get_logger(), + "Skipping canister '{canister}' because it is remote for network '{}'", &network.name, + ); + } + Ok(canister_is_remote) +} From 50d862afb7a0b20d6a8166464d9971c3c367d0e0 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Tue, 26 Nov 2024 00:35:49 -0800 Subject: [PATCH 11/11] changelog --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5396853a28..b881a07b46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,18 @@ Added a flag `--replica` to `dfx start`. This flag currently has no effect. Once PocketIC becomes the default for `dfx start` this flag will start the replica instead. You can use the `--replica` flag already to write scripts that anticipate that change. +### fix: all commands with --all parameter skip remote canisters + +This affects the following commands: +- `dfx canister delete` +- `dfx canister deposit-cycles` +- `dfx canister start` +- `dfx canister status` +- `dfx canister stop` +- `dfx canister uninstall-code` +- `dfx canister update-settings` +- `dfx ledger fabricate-cycles` + # 0.24.3 ### feat: Bitcoin support in PocketIC