diff --git a/src/dfx-core/src/canister/mod.rs b/src/dfx-core/src/canister/mod.rs index beb9ffe126..e57d7c16a0 100644 --- a/src/dfx-core/src/canister/mod.rs +++ b/src/dfx-core/src/canister/mod.rs @@ -72,7 +72,7 @@ YOU WILL LOSE ALL DATA IN THE CANISTER. .map_err(CanisterInstallError::InstallWasmError) } CallSender::Impersonate(_) => { - unreachable!("Impersonating sender is not supported for canister installation.") + unreachable!("Impersonating sender when installing canisters is not supported.") } CallSender::Wallet(wallet_id) => { let wallet = build_wallet_canister(*wallet_id, agent).await?; diff --git a/src/dfx/src/commands/canister/request_status.rs b/src/dfx/src/commands/canister/request_status.rs index 5b8f173268..c481bcf798 100644 --- a/src/dfx/src/commands/canister/request_status.rs +++ b/src/dfx/src/commands/canister/request_status.rs @@ -9,10 +9,7 @@ use backoff::ExponentialBackoff; use candid::Principal; use clap::Parser; use ic_agent::agent::RequestStatusResponse; -use ic_agent::agent::{RejectCode, RejectResponse}; use ic_agent::{AgentError, RequestId}; -use pocket_ic::common::rest::{RawEffectivePrincipal, RawMessageId}; -use pocket_ic::WasmResult; use std::str::FromStr; /// Requests the status of a call from a canister. @@ -53,66 +50,33 @@ pub async fn exec(env: &dyn Environment, opts: RequestStatusOpts) -> DfxResult { let blob = async { let mut request_accepted = false; loop { - if let Some(pocketic_handle) = env.get_pocketic() { - let msg_id = RawMessageId { - effective_principal: RawEffectivePrincipal::CanisterId( - canister_id.as_slice().to_vec(), - ), - message_id: request_id.as_slice().to_vec(), - }; - if let Some(status) = pocketic_handle.ingress_status(msg_id).await { - match status { - Ok(WasmResult::Reply(data)) => return Ok(data), - Ok(WasmResult::Reject(reject_message)) => { - // https://github.com/dfinity/ic/blob/2845f3a1e81eb9eddc0e5541c5565bf6cff898d0/rs/canonical_state/src/lazy_tree_conversion.rs#L509-L513 - let reject = RejectResponse { - reject_code: RejectCode::CanisterReject, - reject_message, - error_code: Some("IC0406".to_string()), // https://github.com/dfinity/ic/blob/2845f3a1e81eb9eddc0e5541c5565bf6cff898d0/rs/types/error_types/src/lib.rs#L204 - }; - return Err(DfxError::new(AgentError::CertifiedReject(reject))); - } - Err(user_error) => { - let error_code_as_u64 = user_error.code as u64; - let derived_reject_code = error_code_as_u64 / 100; - let reject = RejectResponse { - reject_code: derived_reject_code.try_into().unwrap(), - reject_message: user_error.description, - error_code: Some(user_error.code.to_string()), - }; - return Err(DfxError::new(AgentError::CertifiedReject(reject))); - } - } + match agent + .request_status_raw(&request_id, canister_id) + .await + .context("Failed to fetch request status.")? + { + RequestStatusResponse::Replied(reply) => return Ok(reply.arg), + RequestStatusResponse::Rejected(response) => { + return Err(DfxError::new(AgentError::CertifiedReject(response))) } - } else { - match agent - .request_status_raw(&request_id, canister_id) - .await - .context("Failed to fetch request status.")? - { - RequestStatusResponse::Replied(reply) => return Ok(reply.arg), - RequestStatusResponse::Rejected(response) => { - return Err(DfxError::new(AgentError::CertifiedReject(response))) - } - RequestStatusResponse::Unknown => (), - RequestStatusResponse::Received | RequestStatusResponse::Processing => { - // The system will return Unknown until the request is accepted - // and we generally cannot know how long that will take. - // State transitions between Received and Processing may be - // instantaneous. Therefore, once we know the request is accepted, - // we restart the waiter so the request does not time out. - if !request_accepted { - retry_policy.reset(); - request_accepted = true; - } - } - RequestStatusResponse::Done => { - return Err(DfxError::new(AgentError::RequestStatusDoneNoReply( - String::from(request_id), - ))) + RequestStatusResponse::Unknown => (), + RequestStatusResponse::Received | RequestStatusResponse::Processing => { + // The system will return Unknown until the request is accepted + // and we generally cannot know how long that will take. + // State transitions between Received and Processing may be + // instantaneous. Therefore, once we know the request is accepted, + // we restart the waiter so the request does not time out. + if !request_accepted { + retry_policy.reset(); + request_accepted = true; } - }; - } + } + RequestStatusResponse::Done => { + return Err(DfxError::new(AgentError::RequestStatusDoneNoReply( + String::from(request_id), + ))) + } + }; let interval = retry_policy .next_backoff() diff --git a/src/dfx/src/lib/operations/canister/create_canister.rs b/src/dfx/src/lib/operations/canister/create_canister.rs index a118af8bed..7ce30bbea4 100644 --- a/src/dfx/src/lib/operations/canister/create_canister.rs +++ b/src/dfx/src/lib/operations/canister/create_canister.rs @@ -174,7 +174,7 @@ The command line value will be used.", } } CallSender::Impersonate(_) => { - unreachable!("Impersonating sender when creating canisters in not supported.") + unreachable!("Impersonating sender when creating canisters is not supported.") } CallSender::Wallet(wallet_id) => { create_with_wallet(agent, &wallet_id, with_cycles, settings, subnet_selection).await diff --git a/src/dfx/src/lib/operations/canister/mod.rs b/src/dfx/src/lib/operations/canister/mod.rs index b81b3e7570..91b3f46ec8 100644 --- a/src/dfx/src/lib/operations/canister/mod.rs +++ b/src/dfx/src/lib/operations/canister/mod.rs @@ -137,7 +137,7 @@ where } CallSender::Impersonate(_) => { unreachable!( - "Impersonating sender in management canister query calls in not supported." + "Impersonating sender in management canister query calls is not supported." ) } CallSender::Wallet(wallet_id) => {