Canister cycle consumption calculation

I want to know how to calculate the cycle consumption when calling the canister update method. Can someone help me

With the next release of dfx you will be able to try it out locally during development. Until then, you can have a look here: Computation and Storage Costs :: Internet Computer

3 Likes

I want to check the specific calculation process. Can you help me find the specific code file

It’s somewhere in the dfinity/ic repo probably. I’d start searching here: ic/lib.rs at master · dfinity/ic · GitHub

But I’m not familiar with that codebase. I’ll ping internally and see if someone knows it more precisely.

I saw execute_canister_message this method, maybe this

To estimate the cycle consumption you need to know approximately how many Wasm instructions are executed by the update call.

Conversion of the number of executed Wasm instructions to cycles is done in withdraw_execution_cycles of CyclesAccountManager: ic/lib.rs at master · dfinity/ic · GitHub

Note that some system APIs are counted as multiple instructions depending on their overhead: Heads-Up: Fixing PROD issue by adjusting the complexity of some System API calls

2 Likes