I am operating a logic that supplies cycles to multiple canisters, but if I supply cycles in a loop and make multiple deposits and panic occurs in the middle, is there a possibility that the cycles already deposited will not be reverted?
Does it exist as a known event for the platform? If not, is it some kind of developer-specific issue, such as an implementation problem?
The logic is as follows.
#[update]
#[candid_method(update)]
async fn refuel() {
ic_cdk::println!("Start refueling...");
for target in get_refuel_targets() {
let res = canister_status(CanisterIdRecord {
canister_id: target.id,
})
.await;
if let Ok(status) = res {
let balance = status.0.cycles;
if balance > target.threshold {
continue;
}
}
deposit_cycles(
CanisterIdRecord {
canister_id: target.id,
},
target.amount,
)
.await
.unwrap();
}
}
# Dependencies codes
use ic_cdk::{
api::{
management_canister::{
main::{canister_status, deposit_cycles},
},
...
},
...
};
#[derive(CandidType, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
pub struct RefuelTarget {
pub id: Principal,
pub amount: u128,
pub threshold: u128,
}
#[query]
#[candid_method(query)]
fn get_refuel_targets() -> Vec<RefuelTarget> {
REFUEL_TARGETS.with(|m| m.borrow().iter().map(|s| s.clone()).collect::<Vec<_>>())
}