From 9dc5e6ac2764de0ea54ca2c040432dbd934e026b Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 16 Nov 2020 16:14:05 -0800 Subject: [PATCH 01/14] Update agent-rs: use read_state rather than request_status --- Cargo.lock | 6 +++--- Cargo.toml | 15 +++++++++------ nix/sources.json | 2 +- public/manifest.json | 2 +- src/dfx/Cargo.toml | 15 +++++++++------ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 337e26c8ab..5ce1829d53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,7 +1722,7 @@ dependencies = [ [[package]] name = "ic-agent" version = "0.1.0" -source = "git+https://github.com/dfinity/agent-rs.git?branch=next#6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "async-trait", "base32", @@ -1750,7 +1750,7 @@ dependencies = [ [[package]] name = "ic-types" version = "0.1.2" -source = "git+https://github.com/dfinity/agent-rs.git?branch=next#6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "base32", "crc32fast", @@ -1762,7 +1762,7 @@ dependencies = [ [[package]] name = "ic-utils" version = "0.1.0" -source = "git+https://github.com/dfinity/agent-rs.git?branch=next#6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "async-trait", "candid", diff --git a/Cargo.toml b/Cargo.toml index 19e9312853..2463a2e2ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,18 +5,21 @@ members = [ [patch.crates-io.ic-agent] version = "0.1.0" +#path = "../agent-rs/ic-agent" git = "https://github.com/dfinity/agent-rs.git" -branch = "next" -rev = "6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [patch.crates-io.ic-types] version = "0.1.2" +#path = "../agent-rs/ic-types" git = "https://github.com/dfinity/agent-rs.git" -branch = "next" -rev = "6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [patch.crates-io.ic-utils] version = "0.1.0" +#path = "../agent-rs/ic-utils" git = "https://github.com/dfinity/agent-rs.git" -branch = "next" -rev = "6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" diff --git a/nix/sources.json b/nix/sources.json index ebb783645a..33791cee39 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -46,7 +46,7 @@ "ic-ref": { "branch": "release-0.13", "repo": "ssh://git@github.com/dfinity-lab/ic-ref", - "rev": "d08472d437c95534ee3d09e635a370522ea0fd37", + "rev": "96deb731a6544371150d477cf2ac20c22f34164c", "type": "git" }, "motoko": { diff --git a/public/manifest.json b/public/manifest.json index 57e5568193..f419b9a8ec 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,6 +1,6 @@ { "tags": { - "latest": "0.6.14" + "latest": "0.6.13" }, "versions": [ "0.5.0", diff --git a/src/dfx/Cargo.toml b/src/dfx/Cargo.toml index c0dbcfd2cd..69cd114f29 100644 --- a/src/dfx/Cargo.toml +++ b/src/dfx/Cargo.toml @@ -69,21 +69,24 @@ wasmparser = "0.45.0" [dependencies.ic-agent] version = "0.1.0" +#path = "../../../agent-rs/ic-agent" git = "https://github.com/dfinity/agent-rs.git" -branch = "next" -rev = "6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dependencies.ic-types] version = "0.1.2" +#path = "../../../agent-rs/ic-types" git = "https://github.com/dfinity/agent-rs.git" -branch = "next" -rev = "6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dependencies.ic-utils] version = "0.1.0" +#path = "../../../agent-rs/ic-utils" git = "https://github.com/dfinity/agent-rs.git" -branch = "next" -rev = "6c02ef4bf25d82652ceb60c93b9df1a8863f0524" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dev-dependencies] env_logger = "0.6" From a85808d67c65b7884a5cd94acc99d67fd3acd533 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 16 Nov 2020 16:15:33 -0800 Subject: [PATCH 02/14] fetch root key --- Cargo.lock | 7 ++---- Cargo.toml | 24 +++++++++---------- nix/sources.json | 4 ++-- public/manifest.json | 2 +- src/dfx/Cargo.toml | 24 +++++++++---------- src/dfx/src/commands/canister/call.rs | 3 +++ src/dfx/src/commands/canister/create.rs | 3 +++ src/dfx/src/commands/canister/delete.rs | 3 +++ src/dfx/src/commands/canister/install.rs | 3 +++ .../src/commands/canister/request_status.rs | 3 +++ .../src/commands/canister/set_controller.rs | 2 ++ src/dfx/src/commands/canister/start.rs | 3 +++ src/dfx/src/commands/canister/stop.rs | 3 +++ src/dfx/src/commands/deploy.rs | 2 ++ src/dfx/src/lib/error/mod.rs | 24 +++++++++++++++++-- src/dfx/src/lib/mod.rs | 1 + src/dfx/src/lib/root_key.rs | 18 ++++++++++++++ 17 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 src/dfx/src/lib/root_key.rs diff --git a/Cargo.lock b/Cargo.lock index 5ce1829d53..9177aa4cd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,7 +1722,6 @@ dependencies = [ [[package]] name = "ic-agent" version = "0.1.0" -source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "async-trait", "base32", @@ -1750,7 +1749,6 @@ dependencies = [ [[package]] name = "ic-types" version = "0.1.2" -source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "base32", "crc32fast", @@ -1762,7 +1760,6 @@ dependencies = [ [[package]] name = "ic-utils" version = "0.1.0" -source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "async-trait", "candid", @@ -3747,9 +3744,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1e9a0b71dba18b6fa17c7b3dcf1440bb3522552deb2f84bf47dabd9fb7e5570" +checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" dependencies = [ "tinyvec", ] diff --git a/Cargo.toml b/Cargo.toml index 2463a2e2ef..b20d60aaab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,21 +5,21 @@ members = [ [patch.crates-io.ic-agent] version = "0.1.0" -#path = "../agent-rs/ic-agent" -git = "https://github.com/dfinity/agent-rs.git" -branch = "es-wip-resp-auth" -rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +path = "../agent-rs/ic-agent" +#git = "https://github.com/dfinity/agent-rs.git" +#branch = "es-wip-resp-auth" +#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [patch.crates-io.ic-types] version = "0.1.2" -#path = "../agent-rs/ic-types" -git = "https://github.com/dfinity/agent-rs.git" -branch = "es-wip-resp-auth" -rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +path = "../agent-rs/ic-types" +#git = "https://github.com/dfinity/agent-rs.git" +#branch = "es-wip-resp-auth" +#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [patch.crates-io.ic-utils] version = "0.1.0" -#path = "../agent-rs/ic-utils" -git = "https://github.com/dfinity/agent-rs.git" -branch = "es-wip-resp-auth" -rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +path = "../agent-rs/ic-utils" +#git = "https://github.com/dfinity/agent-rs.git" +#branch = "es-wip-resp-auth" +#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" diff --git a/nix/sources.json b/nix/sources.json index 33791cee39..44a3fb9edf 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -44,9 +44,9 @@ "type": "git" }, "ic-ref": { - "branch": "release-0.13", + "branch": "release-0.11", "repo": "ssh://git@github.com/dfinity-lab/ic-ref", - "rev": "96deb731a6544371150d477cf2ac20c22f34164c", + "rev": "9edd0fdda006519118ed40515b84c74f69c59bc1", "type": "git" }, "motoko": { diff --git a/public/manifest.json b/public/manifest.json index f419b9a8ec..57e5568193 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,6 +1,6 @@ { "tags": { - "latest": "0.6.13" + "latest": "0.6.14" }, "versions": [ "0.5.0", diff --git a/src/dfx/Cargo.toml b/src/dfx/Cargo.toml index 69cd114f29..be17d6f10f 100644 --- a/src/dfx/Cargo.toml +++ b/src/dfx/Cargo.toml @@ -69,24 +69,24 @@ wasmparser = "0.45.0" [dependencies.ic-agent] version = "0.1.0" -#path = "../../../agent-rs/ic-agent" -git = "https://github.com/dfinity/agent-rs.git" -branch = "es-wip-resp-auth" -rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +path = "../../../agent-rs/ic-agent" +#git = "https://github.com/dfinity/agent-rs.git" +#branch = "es-wip-resp-auth" +#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dependencies.ic-types] version = "0.1.2" -#path = "../../../agent-rs/ic-types" -git = "https://github.com/dfinity/agent-rs.git" -branch = "es-wip-resp-auth" -rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +path = "../../../agent-rs/ic-types" +#git = "https://github.com/dfinity/agent-rs.git" +#branch = "es-wip-resp-auth" +#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dependencies.ic-utils] version = "0.1.0" -#path = "../../../agent-rs/ic-utils" -git = "https://github.com/dfinity/agent-rs.git" -branch = "es-wip-resp-auth" -rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +path = "../../../agent-rs/ic-utils" +#git = "https://github.com/dfinity/agent-rs.git" +#branch = "es-wip-resp-auth" +#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dev-dependencies] env_logger = "0.6" diff --git a/src/dfx/src/commands/canister/call.rs b/src/dfx/src/commands/canister/call.rs index c7ca361762..163d6b5c78 100644 --- a/src/dfx/src/commands/canister/call.rs +++ b/src/dfx/src/commands/canister/call.rs @@ -2,6 +2,7 @@ use crate::lib::canister_info::CanisterInfo; use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; use crate::lib::models::canister_id_store::CanisterIdStore; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::{blob_from_arguments, expiry_duration, get_candid_type, print_idl_blob}; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -110,6 +111,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { .ok_or(DfxError::CommandMustBeRunInAProject)?; let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + let timeout = expiry_duration(); if is_query { diff --git a/src/dfx/src/commands/canister/create.rs b/src/dfx/src/commands/canister/create.rs index 7174e2a957..5b2ac821ee 100644 --- a/src/dfx/src/commands/canister/create.rs +++ b/src/dfx/src/commands/canister/create.rs @@ -1,6 +1,7 @@ use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; use crate::lib::operations::canister::create_canister; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; use tokio::runtime::Runtime; @@ -32,6 +33,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + if let Some(canister_name) = opts.canister_name { runtime.block_on(create_canister(env, canister_name.as_str(), timeout))?; Ok(()) diff --git a/src/dfx/src/commands/canister/delete.rs b/src/dfx/src/commands/canister/delete.rs index a88658bcf0..aaad71e456 100644 --- a/src/dfx/src/commands/canister/delete.rs +++ b/src/dfx/src/commands/canister/delete.rs @@ -1,6 +1,7 @@ use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; use crate::lib::models::canister_id_store::CanisterIdStore; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -67,6 +68,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + if let Some(canister_name) = opts.canister_name.as_deref() { runtime.block_on(delete_canister(env, &agent, canister_name, timeout))?; Ok(()) diff --git a/src/dfx/src/commands/canister/install.rs b/src/dfx/src/commands/canister/install.rs index 057ab40f1b..b2642784c1 100644 --- a/src/dfx/src/commands/canister/install.rs +++ b/src/dfx/src/commands/canister/install.rs @@ -4,6 +4,7 @@ use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; use crate::lib::models::canister_id_store::CanisterIdStore; use crate::lib::operations::canister::install_canister; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::util::clap::validators::{compute_allocation_validator, memory_allocation_validator}; use crate::util::{blob_from_arguments, expiry_duration, get_candid_init_type}; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -99,6 +100,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + let canister_id_store = CanisterIdStore::for_env(env)?; if let Some(canister_name) = opts.canister_name.as_deref() { diff --git a/src/dfx/src/commands/canister/request_status.rs b/src/dfx/src/commands/canister/request_status.rs index 04cedf601a..f89460590b 100644 --- a/src/dfx/src/commands/canister/request_status.rs +++ b/src/dfx/src/commands/canister/request_status.rs @@ -1,5 +1,6 @@ use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::clap::validators; use crate::util::{expiry_duration, print_idl_blob}; @@ -34,6 +35,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { .ok_or(DfxError::CommandMustBeRunInAProject)?; let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + let timeout = expiry_duration(); let mut waiter = waiter_with_timeout(timeout); diff --git a/src/dfx/src/commands/canister/set_controller.rs b/src/dfx/src/commands/canister/set_controller.rs index 73090c128a..b188b20d9b 100644 --- a/src/dfx/src/commands/canister/set_controller.rs +++ b/src/dfx/src/commands/canister/set_controller.rs @@ -2,6 +2,7 @@ use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; use crate::lib::identity::identity_manager::IdentityManager; use crate::lib::models::canister_id_store::CanisterIdStore; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -49,6 +50,7 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { ); let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; runtime.block_on( mgr.set_controller(&canister_id, &controller_principal) .call_and_wait(waiter_with_timeout(timeout)), diff --git a/src/dfx/src/commands/canister/start.rs b/src/dfx/src/commands/canister/start.rs index 8cf0a3d9b5..14a5c49ea4 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::{DfxError, DfxResult}; use crate::lib::models::canister_id_store::CanisterIdStore; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -64,6 +65,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + let timeout = expiry_duration(); if let Some(canister_name) = opts.canister_name.as_deref() { diff --git a/src/dfx/src/commands/canister/stop.rs b/src/dfx/src/commands/canister/stop.rs index cb78e48e35..acfc995864 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::{DfxError, DfxResult}; use crate::lib::models::canister_id_store::CanisterIdStore; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -63,6 +64,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { .ok_or(DfxError::CommandMustBeRunInAProject)?; let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + let timeout = expiry_duration(); if let Some(canister_name) = opts.canister_name.as_deref() { diff --git a/src/dfx/src/commands/deploy.rs b/src/dfx/src/commands/deploy.rs index c798a03224..b8ae2fdb20 100644 --- a/src/dfx/src/commands/deploy.rs +++ b/src/dfx/src/commands/deploy.rs @@ -2,6 +2,7 @@ use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::operations::canister::deploy_canisters; use crate::lib::provider::create_agent_environment; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; use tokio::runtime::Runtime; @@ -41,6 +42,7 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { let argument_type = opts.argument_type.as_deref(); let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(&env))?; runtime.block_on(deploy_canisters( &env, diff --git a/src/dfx/src/lib/error/mod.rs b/src/dfx/src/lib/error/mod.rs index fd0a26786a..578d78ad46 100644 --- a/src/dfx/src/lib/error/mod.rs +++ b/src/dfx/src/lib/error/mod.rs @@ -194,8 +194,19 @@ impl Display for DfxError { reject_code, reject_message ))?; } - DfxError::AgentError(AgentError::HttpError(http_error_payload)) => { - f.write_fmt(format_args!("Replica error: {}", http_error_payload))?; + DfxError::AgentError(AgentError::HttpError { + status, + content_type, + content, + }) if is_plain_text_utf8(content_type) => { + f.write_fmt(format_args!( + "Replica error (HTTP status {}): {}", + status, + String::from_utf8(content.to_vec()).unwrap_or_else(|from_utf8_err| format!( + "(unable to decode content: {:#?})", + from_utf8_err + )) + ))?; } DfxError::Unknown(err) => { f.write_fmt(format_args!("Unknown error: {}", err))?; @@ -330,3 +341,12 @@ impl From for DfxError { DfxError::WaiterError(err) } } + +fn is_plain_text_utf8(content_type: &Option) -> bool { + // text/plain is also sometimes returned by the replica (or ic-ref), + // depending on where in the stack the error happens. + matches!( + content_type.as_ref().and_then(|s|s.parse::().ok()), + Some(mt) if mt == mime::TEXT_PLAIN || mt == mime::TEXT_PLAIN_UTF_8 + ) +} diff --git a/src/dfx/src/lib/mod.rs b/src/dfx/src/lib/mod.rs index bfbe4ed842..28b6c7e319 100644 --- a/src/dfx/src/lib/mod.rs +++ b/src/dfx/src/lib/mod.rs @@ -14,5 +14,6 @@ pub mod package_arguments; pub mod progress_bar; pub mod provider; pub mod replica_config; +pub mod root_key; pub mod waiter; pub mod webserver; diff --git a/src/dfx/src/lib/root_key.rs b/src/dfx/src/lib/root_key.rs new file mode 100644 index 0000000000..908ded7e5c --- /dev/null +++ b/src/dfx/src/lib/root_key.rs @@ -0,0 +1,18 @@ +use crate::lib::environment::Environment; +use crate::lib::error::{DfxError, DfxResult}; + +pub async fn fetch_root_key_if_needed<'a>(env: &'a (dyn Environment + 'a)) -> DfxResult { + let must_fetch_root_key = env + .get_network_descriptor() + .map(|nd| nd.name != "ic") + .unwrap_or(true); + + if must_fetch_root_key { + let agent = env + .get_agent() + .ok_or(DfxError::CommandMustBeRunInAProject)?; + + agent.fetch_root_key().await?; + } + Ok(()) +} From df33efa7043f53891a8afdea73c171b9f22f3253 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 16 Nov 2020 17:59:04 -0800 Subject: [PATCH 03/14] use es-wip-resp-auth --- Cargo.lock | 3 +++ Cargo.toml | 24 ++++++++++++------------ src/dfx/Cargo.toml | 24 ++++++++++++------------ 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9177aa4cd2..df2cdff7ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,6 +1722,7 @@ dependencies = [ [[package]] name = "ic-agent" version = "0.1.0" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#4dd2161e7a1725269b07bf3c1ee3b2c8162aa7a2" dependencies = [ "async-trait", "base32", @@ -1749,6 +1750,7 @@ dependencies = [ [[package]] name = "ic-types" version = "0.1.2" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#4dd2161e7a1725269b07bf3c1ee3b2c8162aa7a2" dependencies = [ "base32", "crc32fast", @@ -1760,6 +1762,7 @@ dependencies = [ [[package]] name = "ic-utils" version = "0.1.0" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#4dd2161e7a1725269b07bf3c1ee3b2c8162aa7a2" dependencies = [ "async-trait", "candid", diff --git a/Cargo.toml b/Cargo.toml index b20d60aaab..2463a2e2ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,21 +5,21 @@ members = [ [patch.crates-io.ic-agent] version = "0.1.0" -path = "../agent-rs/ic-agent" -#git = "https://github.com/dfinity/agent-rs.git" -#branch = "es-wip-resp-auth" -#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +#path = "../agent-rs/ic-agent" +git = "https://github.com/dfinity/agent-rs.git" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [patch.crates-io.ic-types] version = "0.1.2" -path = "../agent-rs/ic-types" -#git = "https://github.com/dfinity/agent-rs.git" -#branch = "es-wip-resp-auth" -#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +#path = "../agent-rs/ic-types" +git = "https://github.com/dfinity/agent-rs.git" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [patch.crates-io.ic-utils] version = "0.1.0" -path = "../agent-rs/ic-utils" -#git = "https://github.com/dfinity/agent-rs.git" -#branch = "es-wip-resp-auth" -#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +#path = "../agent-rs/ic-utils" +git = "https://github.com/dfinity/agent-rs.git" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" diff --git a/src/dfx/Cargo.toml b/src/dfx/Cargo.toml index be17d6f10f..69cd114f29 100644 --- a/src/dfx/Cargo.toml +++ b/src/dfx/Cargo.toml @@ -69,24 +69,24 @@ wasmparser = "0.45.0" [dependencies.ic-agent] version = "0.1.0" -path = "../../../agent-rs/ic-agent" -#git = "https://github.com/dfinity/agent-rs.git" -#branch = "es-wip-resp-auth" -#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +#path = "../../../agent-rs/ic-agent" +git = "https://github.com/dfinity/agent-rs.git" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dependencies.ic-types] version = "0.1.2" -path = "../../../agent-rs/ic-types" -#git = "https://github.com/dfinity/agent-rs.git" -#branch = "es-wip-resp-auth" -#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +#path = "../../../agent-rs/ic-types" +git = "https://github.com/dfinity/agent-rs.git" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dependencies.ic-utils] version = "0.1.0" -path = "../../../agent-rs/ic-utils" -#git = "https://github.com/dfinity/agent-rs.git" -#branch = "es-wip-resp-auth" -#rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" +#path = "../../../agent-rs/ic-utils" +git = "https://github.com/dfinity/agent-rs.git" +branch = "es-wip-resp-auth" +rev = "d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" [dev-dependencies] env_logger = "0.6" From cbc27acc56d4c1186326c1c2ec3d0fd09d744bab Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Mon, 16 Nov 2020 18:00:32 -0800 Subject: [PATCH 04/14] http error payload something --- src/dfx/src/lib/error/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dfx/src/lib/error/mod.rs b/src/dfx/src/lib/error/mod.rs index 578d78ad46..719524a178 100644 --- a/src/dfx/src/lib/error/mod.rs +++ b/src/dfx/src/lib/error/mod.rs @@ -1,4 +1,4 @@ -use ic_agent::AgentError; +use ic_agent::{AgentError, HttpErrorPayload}; use ic_types::principal::PrincipalError; mod build; @@ -194,11 +194,11 @@ impl Display for DfxError { reject_code, reject_message ))?; } - DfxError::AgentError(AgentError::HttpError { + DfxError::AgentError(AgentError::HttpError(HttpErrorPayload { status, content_type, content, - }) if is_plain_text_utf8(content_type) => { + })) if is_plain_text_utf8(content_type) => { f.write_fmt(format_args!( "Replica error (HTTP status {}): {}", status, From cff608c13921449dd4e39a1a41a61d7e165a8e47 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Tue, 17 Nov 2020 17:38:12 -0800 Subject: [PATCH 05/14] Update ic-ref to release-0.13 --- nix/sources.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index 44a3fb9edf..ebb783645a 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -44,9 +44,9 @@ "type": "git" }, "ic-ref": { - "branch": "release-0.11", + "branch": "release-0.13", "repo": "ssh://git@github.com/dfinity-lab/ic-ref", - "rev": "9edd0fdda006519118ed40515b84c74f69c59bc1", + "rev": "d08472d437c95534ee3d09e635a370522ea0fd37", "type": "git" }, "motoko": { From 4f5b91b234ccdd6453c09a0e84bfca1180463661 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 13:53:04 -0800 Subject: [PATCH 06/14] fix build.bash e2e tests --- e2e/bats/build.bash | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/e2e/bats/build.bash b/e2e/bats/build.bash index 57456679a1..4f90f8e657 100644 --- a/e2e/bats/build.bash +++ b/e2e/bats/build.bash @@ -94,9 +94,10 @@ teardown() { dfx_start webserver_port=$(cat .dfx/webserver-port) - assert_command dfx config networks.ic.providers '[ "http://127.0.0.1:'$webserver_port'" ]' - assert_command dfx canister --network ic create --all - assert_command dfx build --network ic + cat <<<$(jq .networks.actuallylocal.providers=[\"http://127.0.0.1:$webserver_port\"] dfx.json) >dfx.json + + assert_command dfx canister --network actuallylocal create --all + assert_command dfx build --network actuallylocal } @test "build output for local network is in expected directory" { @@ -110,10 +111,10 @@ teardown() { @test "build output for non-local network is in expected directory" { dfx_start webserver_port=$(cat .dfx/webserver-port) - assert_command dfx config networks.ic.providers '[ "http://127.0.0.1:'$webserver_port'" ]' - dfx canister --network ic create --all - assert_command dfx build --network ic - assert_command ls .dfx/ic/canisters/e2e_project/ - assert_command ls .dfx/ic/canisters/e2e_project/e2e_project.wasm + cat <<<$(jq .networks.actuallylocal.providers=[\"http://127.0.0.1:$webserver_port\"] dfx.json) >dfx.json + dfx canister --network actuallylocal create --all + assert_command dfx build --network actuallylocal + assert_command ls .dfx/actuallylocal/canisters/e2e_project/ + assert_command ls .dfx/actuallylocal/canisters/e2e_project/e2e_project.wasm } From 91cbd9a32889caf9e441fbc019598e674c0ff24a Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 13:56:53 -0800 Subject: [PATCH 07/14] fix create.bash e2e tests --- e2e/bats/create.bash | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/e2e/bats/create.bash b/e2e/bats/create.bash index 9d82fa17ff..f67237c1ad 100644 --- a/e2e/bats/create.bash +++ b/e2e/bats/create.bash @@ -53,21 +53,22 @@ teardown() { dfx_start webserver_port=$(cat .dfx/webserver-port) - assert_command dfx config networks.ic.providers '[ "http://127.0.0.1:'$webserver_port'" ]' - assert_command dfx canister --network ic create --all + cat <<<$(jq .networks.actuallylocal.providers=[\"http://127.0.0.1:$webserver_port\"] dfx.json) >dfx.json + assert_command dfx canister --network actuallylocal create --all } @test "create fails if selected network exists but has no providers" { dfx_start assert_command dfx config networks.ic.providers '[ ]' - assert_command_fail dfx canister --network ic create --all + cat <<<$(jq .networks.actuallylocal.providers=[] dfx.json) >dfx.json + assert_command_fail dfx canister --network actuallylocal create --all assert_match "ComputeNetworkHasNoProviders" } @test "create fails with network parameter when network does not exist" { dfx_start - assert_command dfx config networks.ic.providers '[ "http://not-real.nowhere.test." ]' - assert_command_fail dfx canister --network ic create --all + cat <<<$(jq .networks.actuallylocal.providers=[\"http://not-real.nowhere.test.\"] dfx.json) >dfx.json + assert_command_fail dfx canister --network actuallylocal create --all assert_match "ConnectError" } From 0c2ae7da66e7b45e81905a26bb31c3f219e55d63 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 14:01:36 -0800 Subject: [PATCH 08/14] fix network.bash e2e test --- e2e/bats/network.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e/bats/network.bash b/e2e/bats/network.bash index b3821d34af..9e51c0514e 100644 --- a/e2e/bats/network.bash +++ b/e2e/bats/network.bash @@ -18,27 +18,27 @@ teardown() { dfx_start webserver_port=$(cat .dfx/webserver-port) - assert_command dfx config networks.ic.providers '[ "http://127.0.0.1:'$webserver_port'" ]' + cat <<<$(jq .networks.actuallylocal.providers=[\"http://127.0.0.1:$webserver_port\"] dfx.json) >dfx.json - assert_command dfx canister --network ic create --all + assert_command dfx canister --network actuallylocal create --all # canister creates writes to a spinner (stderr), not stdout - assert_command dfx canister --network ic id e2e_project - assert_match $(cat canister_ids.json | jq -r .e2e_project.ic) + assert_command dfx canister --network actuallylocal id e2e_project + assert_match $(cat canister_ids.json | jq -r .e2e_project.actuallylocal) } @test "create stores canister ids for configured-ephemeral networks in canister_ids.json" { dfx_start webserver_port=$(cat .dfx/webserver-port) - assert_command dfx config networks.ic.providers '[ "http://127.0.0.1:'$webserver_port'" ]' - cat <<<$(jq .networks.ic.type=\"ephemeral\" dfx.json) >dfx.json + cat <<<$(jq .networks.actuallylocal.providers=[\"http://127.0.0.1:$webserver_port\"] dfx.json) >dfx.json + cat <<<$(jq .networks.actuallylocal.type=\"ephemeral\" dfx.json) >dfx.json - assert_command dfx canister --network ic create --all + assert_command dfx canister --network actuallylocal create --all # canister creates writes to a spinner (stderr), not stdout - assert_command dfx canister --network ic id e2e_project - assert_match $(cat .dfx/ic/canister_ids.json | jq -r .e2e_project.ic) + assert_command dfx canister --network actuallylocal id e2e_project + assert_match $(cat .dfx/actuallylocal/canister_ids.json | jq -r .e2e_project.actuallylocal) } @test "create stores canister ids for default-ephemeral local networks in .dfx/{network}canister_ids.json" { @@ -74,8 +74,8 @@ teardown() { dfx_start webserver_port=$(cat .dfx/webserver-port) - assert_command dfx config networks.ic.providers '[ "http://127.0.0.1:'$webserver_port'" ]' + cat <<<$(jq .networks.actuallylocal.providers=[\"http://127.0.0.1:$webserver_port\"] dfx.json) >dfx.json - assert_command_fail dfx build --network ic - assert_match "Cannot find canister id. Please issue 'dfx canister --network ic create e2e_project" + assert_command_fail dfx build --network actuallylocal + assert_match "Cannot find canister id. Please issue 'dfx canister --network actuallylocal create e2e_project" } From 0353635df879ac85f7f51f6f6117d62ca1b9c0f7 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 14:14:59 -0800 Subject: [PATCH 09/14] canister status needs root key too --- src/dfx/src/commands/canister/status.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dfx/src/commands/canister/status.rs b/src/dfx/src/commands/canister/status.rs index e7fc63e4c5..01e00dfab4 100644 --- a/src/dfx/src/commands/canister/status.rs +++ b/src/dfx/src/commands/canister/status.rs @@ -10,6 +10,7 @@ use ic_utils::interfaces::ManagementCanister; use slog::info; use std::time::Duration; use tokio::runtime::Runtime; +use crate::lib::root_key::fetch_root_key_if_needed; /// Returns the current status of the canister on the Internet Computer network: Running, Stopping, or Stopped. #[derive(Clap)] @@ -59,6 +60,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches) -> DfxResult { let mut runtime = Runtime::new().expect("Unable to create a runtime"); + runtime.block_on(fetch_root_key_if_needed(env))?; + let timeout = expiry_duration(); if let Some(canister_name) = opts.canister_name.as_deref() { From 4bb327c68c913233d282ca6f47d676003e7ca3b4 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 14:34:38 -0800 Subject: [PATCH 10/14] revert HttpErrorPayload stuff; --- src/dfx/src/lib/error/mod.rs | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/dfx/src/lib/error/mod.rs b/src/dfx/src/lib/error/mod.rs index 719524a178..fd0a26786a 100644 --- a/src/dfx/src/lib/error/mod.rs +++ b/src/dfx/src/lib/error/mod.rs @@ -1,4 +1,4 @@ -use ic_agent::{AgentError, HttpErrorPayload}; +use ic_agent::AgentError; use ic_types::principal::PrincipalError; mod build; @@ -194,19 +194,8 @@ impl Display for DfxError { reject_code, reject_message ))?; } - DfxError::AgentError(AgentError::HttpError(HttpErrorPayload { - status, - content_type, - content, - })) if is_plain_text_utf8(content_type) => { - f.write_fmt(format_args!( - "Replica error (HTTP status {}): {}", - status, - String::from_utf8(content.to_vec()).unwrap_or_else(|from_utf8_err| format!( - "(unable to decode content: {:#?})", - from_utf8_err - )) - ))?; + DfxError::AgentError(AgentError::HttpError(http_error_payload)) => { + f.write_fmt(format_args!("Replica error: {}", http_error_payload))?; } DfxError::Unknown(err) => { f.write_fmt(format_args!("Unknown error: {}", err))?; @@ -341,12 +330,3 @@ impl From for DfxError { DfxError::WaiterError(err) } } - -fn is_plain_text_utf8(content_type: &Option) -> bool { - // text/plain is also sometimes returned by the replica (or ic-ref), - // depending on where in the stack the error happens. - matches!( - content_type.as_ref().and_then(|s|s.parse::().ok()), - Some(mt) if mt == mime::TEXT_PLAIN || mt == mime::TEXT_PLAIN_UTF_8 - ) -} From a643b6ba15c5196e59f736b8c9afa4eede0032b0 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 14:40:23 -0800 Subject: [PATCH 11/14] cargo update; --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df2cdff7ba..637f38dba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,7 +1722,7 @@ dependencies = [ [[package]] name = "ic-agent" version = "0.1.0" -source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#4dd2161e7a1725269b07bf3c1ee3b2c8162aa7a2" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "async-trait", "base32", @@ -1750,7 +1750,7 @@ dependencies = [ [[package]] name = "ic-types" version = "0.1.2" -source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#4dd2161e7a1725269b07bf3c1ee3b2c8162aa7a2" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "base32", "crc32fast", @@ -1762,7 +1762,7 @@ dependencies = [ [[package]] name = "ic-utils" version = "0.1.0" -source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#4dd2161e7a1725269b07bf3c1ee3b2c8162aa7a2" +source = "git+https://github.com/dfinity/agent-rs.git?branch=es-wip-resp-auth#d8d2649ad0e4e8bb5328d5e97b6705c5275afe7a" dependencies = [ "async-trait", "candid", From e1e76bd32b1246877058ce3bdd094cd298ca1fea Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Wed, 18 Nov 2020 14:40:37 -0800 Subject: [PATCH 12/14] format --- src/dfx/src/commands/canister/status.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dfx/src/commands/canister/status.rs b/src/dfx/src/commands/canister/status.rs index 01e00dfab4..f558c97c73 100644 --- a/src/dfx/src/commands/canister/status.rs +++ b/src/dfx/src/commands/canister/status.rs @@ -1,6 +1,7 @@ use crate::lib::environment::Environment; use crate::lib::error::{DfxError, DfxResult}; use crate::lib::models::canister_id_store::CanisterIdStore; +use crate::lib::root_key::fetch_root_key_if_needed; use crate::lib::waiter::waiter_with_timeout; use crate::util::expiry_duration; use clap::{App, ArgMatches, Clap, FromArgMatches, IntoApp}; @@ -10,7 +11,6 @@ use ic_utils::interfaces::ManagementCanister; use slog::info; use std::time::Duration; use tokio::runtime::Runtime; -use crate::lib::root_key::fetch_root_key_if_needed; /// Returns the current status of the canister on the Internet Computer network: Running, Stopping, or Stopped. #[derive(Clap)] From a40315022531641912f94af1b9ad4078094df5a1 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Thu, 19 Nov 2020 09:47:36 +0100 Subject: [PATCH 13/14] Bump dfinity some more seems to fix stuff for me --- nix/sources.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/sources.json b/nix/sources.json index ebb783645a..d784a17d09 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -40,7 +40,7 @@ "dfinity": { "branch": "master", "repo": "ssh://git@github.com/dfinity-lab/dfinity", - "rev": "482ba09bfa3a0ac41209684e947e83b8e0c83138", + "rev": "5f20a0a2c15b4b10884ce814db192fa241aca2ff", "type": "git" }, "ic-ref": { From 3558c502c1132052889f1a4067941f91e0d130af Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Thu, 19 Nov 2020 11:16:22 +0100 Subject: [PATCH 14/14] Bump again, to get `--http-port` fix --- nix/sources.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/sources.json b/nix/sources.json index d784a17d09..373a721524 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -40,7 +40,7 @@ "dfinity": { "branch": "master", "repo": "ssh://git@github.com/dfinity-lab/dfinity", - "rev": "5f20a0a2c15b4b10884ce814db192fa241aca2ff", + "rev": "19da081c7fb438f10b25abcb7fee0796ec79ad7b", "type": "git" }, "ic-ref": {