When is Cycles deducted?

I learned that If I end the call using ic_cdk::trap(msg), cycles aren’t deducted.
Is the case same when I’m perform cross canister call, http outcalls before calling the trap?
Will the cycles be deducted?

trap rolls everything (including cycles accepted, attached to calls, …) back to the last commit point (read: await).

From the docs (can recommend you read the full page):

In particular, any state changes made by the canister before making the inter-canister call and calling await to wait for the response will not be rolled back (as this was a separate message execution that happened before the callback handler was invoked).

1 Like

thank you @Severin for sharing, I read it. still had some confusion.
Can you clear this?

let res = ic_cdk::call(canister, "method", ()).await;
if let Err(e) = res{
  ic_cdk::trap("")
}

In this code, cycles will be deducted right?
If it is deducted will it be cycles for calling update method, cycles for inter canister call. am I right?

Yes, that’s right. And if you attach cycles to the call then those will stay with the target canister (assuming it accepts the cycles).