Canister Cycle Limits and Burning Cycles 😬?

Hey all! Can anyone shed some more-official light onto how many cycles a canister can hold? I’ve been experimenting it looks like 10^14.

I’m working on a goofy recreation of the “Million Dollar Homepage”, and my plan was to let “users” buy pixels by sending Cycles along with their request. It all works, but since the canister the full once you deploy to your local replica, all the cycles I send just get refunded.

Is there a way to burn cycles that isn’t just executing a big for loop? Maybe a way to extract cycles from a canister? Or, maybe just a way to configure how many cycles the canister is deployed with?

2 Likes

Have you seen this documentation Managing cycles :: Internet Computer?

I suspect your code needs to add a call to ExperimentalCycles.accept(amount : Nat) : Nat to actually accept the funds sent on the call - unless explicitly accepted, the funds will be refunded.

To transfer funds with an intercanister call, call ExperimentalCycles.add(amount : Nat) : () before making the call.

I’m not sure how to arrange for a JS call to transfer funds from the user wallet to your service, but hopefully someone else can answer that one (and your other questions).

Best,
Claudio

2 Likes

Hey @claudio !

I have! The issue I’m having is the canister refunds most of the cycles I send, because I believe I’m at the canister’s cycle capacity already.

Ah, sorry, I didn’t read your question carefully enough.

I’m not aware of any way for dfx to specify the initial cycle allocation for a local install.

As a workaround, which is kinda slow and expensive, you can get your actor to dynamically install a dummy canister using an actor class that you either discard or let hang around. Any cycles you put on the actor class instantiation will be transferred to the fresh canister and die if and when that canister is deleted, freeing up capacity in the main canister.

This repo provides two methods, burn and burnFast, One is slow because it creates and destroys the other canister, requiring more rounds of concensus. The other is fast, because it just leaks the fresh canister after transferring the cycles.

Clearly, this is a hack.

2 Likes

@claudio thank you so much - This Perfect!’

Also,

Didn’t know about these management canister functions. Woo!

1 Like

I’ve cleaned up the examples a bit and added a third method:

  • burn just creates a new actor, passing cycles to it, but doesn’t cleanup the new actor;
  • burnBetter uses the system’s management canister to additionally delete the temporary actor.
  • burnBest uses the system’s management canister to just create and delete an empty canister, without even installing a Motoko actor (or requiring a dummy Motoko actor class).
3 Likes

I’ve been told that dfx 0.6.24 will let you specify cycles on dfx canister create and dfx deploy, so you can avoid the hack.

4 Likes