From 9147059f1d1b44624beceae46234b676669fe9db Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Fri, 22 Dec 2023 10:56:33 +0100 Subject: [PATCH] retry retryable errors --- src/dfx/src/lib/ic_attributes/mod.rs | 2 +- src/dfx/src/lib/operations/cycles_ledger.rs | 45 +++++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/dfx/src/lib/ic_attributes/mod.rs b/src/dfx/src/lib/ic_attributes/mod.rs index 5d91390562..2722283d0a 100644 --- a/src/dfx/src/lib/ic_attributes/mod.rs +++ b/src/dfx/src/lib/ic_attributes/mod.rs @@ -9,7 +9,7 @@ use ic_utils::interfaces::management_canister::attributes::{ }; use std::convert::TryFrom; -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub struct CanisterSettings { pub controllers: Option>, pub compute_allocation: Option, diff --git a/src/dfx/src/lib/operations/cycles_ledger.rs b/src/dfx/src/lib/operations/cycles_ledger.rs index a41b686038..67fd4011e0 100644 --- a/src/dfx/src/lib/operations/cycles_ledger.rs +++ b/src/dfx/src/lib/operations/cycles_ledger.rs @@ -267,23 +267,34 @@ pub async fn create_with_cycles_ledger( Some(now) }); - let result = agent - .update(&cycles_ledger_canister_id, CREATE_CANISTER_METHOD) - .with_arg( - Encode!(&CreateCanisterArgs { - from_subaccount, - created_at_time, - amount: cycles, - creation_args: Some(CmcCreateCanisterArgs { - settings: Some(settings.into()), - subnet_selection: None, - }), - }) - .unwrap(), - ) - .call_and_wait() - .await - .map_err(|err| anyhow!(err))?; + let result = loop { + match agent + .update(&cycles_ledger_canister_id, CREATE_CANISTER_METHOD) + .with_arg( + Encode!(&CreateCanisterArgs { + from_subaccount, + created_at_time, + amount: cycles, + creation_args: Some(CmcCreateCanisterArgs { + settings: Some(settings.clone().into()), + subnet_selection: None, + }), + }) + .unwrap(), + ) + .call_and_wait() + .await + { + Ok(result) => break result, + Err(err) => { + if retryable(&err) { + info!(env.get_logger(), "Request error: {err:?}. Retrying..."); + } else { + bail!(err) + } + } + } + }; let create_result = Decode!( &result, Result