"dfx deploy --with-cycles" does not work as expected

“dfx deploy --with-cycles” does not work as expected.

$ dfx --version
dfx 0.13.1

$ dfx deploy --network ic --with-cycles 200000000000
(Abbreviation)
Deployed canisters.
URLs:
Frontend canister via browser
samples_frontend: https://cpsly-ryaaa-aaaak-aep7a-cai.ic0.app/
Backend canister via Candid interface:
samples_backend: DFINITY Canister Candid UI

$ dfx canister status --all
Canister status call result for samples_backend.
Status: Running
Controllers: 3v2eo-ybud2-stzfo-icwfu-rltti-t35go-w3pyk-ekkbb-aq3ru-ky4vc-oae q4eej-kyaaa-aaaaa-aaaha-cai
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(332470)
Balance: 3_092_280_573_538 Cycles
Module hash: 0x517238bad4ce03ddfb3a0bea28cca827b0dbd494c2e062233b1ea68e9895a8b8
Canister status call result for samples_frontend.
Status: Running
Controllers: 3v2eo-ybud2-stzfo-icwfu-rltti-t35go-w3pyk-ekkbb-aq3ru-ky4vc-oae q4eej-kyaaa-aaaaa-aaaha-cai
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(4419605)
Balance: 3_091_888_656_064 Cycles
Module hash: 0x98863747bb8b1366ae5e3c5721bfe08ce6b7480fe4c3864d4fec3d9827255480

“Balance: 3_092_280_573_538 Cycles” was displayed. Why did it show 3_092_280_573_538 instead of 200_000_000_000? Am I not understanding the specifications? Or is it a bug?

The fact that https://cpsly-ryaaa-aaaak-aep7a-cai.ic0.app/ is 404 is also concerning.

Instead of ic0.app you should use icp0.io. https://cpsly-ryaaa-aaaak-aep7a-cai.icp0.io/

I guess this will be fixed in the next version of dfx.

1 Like

This is not a bug, it’s just how it work, and if you have an idea how to improve it, I’d be very happy to hear your suggestions.

The thing is, --with-cycles only has an effect on canister creation. If you already have the canister created, it doesn’t do anything. So you probably created the canister at an earlier point in time, defaulting to ~3T cycles, and then redeployed with --with-cycles, which did not have an effect

1 Like

@0kenx
Thanks!

@Severin
$ dfx deploy --network ic --with-cycles 1
This resulted in the following error. Perhaps an empty canister was created for 3T cycles?

$ dfx deploy --network ic --with-cycles 1
Deploying all canisters.
Creating canisters…
Creating canister samples_backend…
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
Failed while trying to register all canisters.
Failed to create canister ‘samples_backend’.
The wallet operation failed: An error happened during the call: 4: Creating a canister requires a fee of 100_000_000_000 that is deducted from the canister’s initial balance but only 1 cycles were received with the create_canister request.

$ dfx deploy --network ic --with-cycles 200000000000
Deploying all canisters.
Creating canisters…
Creating canister samples_backend…
samples_backend canister created on network ic with canister id: cgrae-hqaaa-aaaak-aep6q-cai
Creating canister samples_frontend…
samples_frontend canister created on network ic with canister id: cpsly-ryaaa-aaaak-aep7a-cai
Building canisters…
Shrink WASM module size.
Building frontend…
WARN: Building canisters before generate for Motoko
Shrink WASM module size.
Generating type declarations for canister samples_backend:
src/declarations/samples_backend/samples_backend.did.d.ts
src/declarations/samples_backend/samples_backend.did.js
src/declarations/samples_backend/samples_backend.did

Installing canisters…
Installing code for canister samples_backend, with canister ID cgrae-hqaaa-aaaak-aep6q-cai
Installing code for canister samples_frontend, with canister ID cpsly-ryaaa-aaaak-aep7a-cai
Uploading assets to asset canister…
Starting batch.
Staging contents of new and changed assets:
/index.js.LICENSE.txt (gzip) 1/1 (273 bytes) sha db89b3ccdfe399f8ef3135c0b076326a0ae9e1c96409f79f8e686031537c572c (with 7 headers)
/index.js.LICENSE.txt 1/1 (413 bytes) sha f2dcfd36875be0296e171d0a6b1161de82510a3e60f4d54cc1b4bec0829f8b33 (with 7 headers)
/index.js.map 1/1 (682360 bytes) sha 794db1b4832144bfe448c3a71b2c56808c7ff146c5a8b6320bfd2b4296a67d39 (with 7 headers)
/logo2.svg 1/1 (15139 bytes) sha 037eb7ae523403daa588cf4f47a34c56a3f5de08a5a2dd2364839e45f14f4b8b (with 7 headers)
/index.html (gzip) 1/1 (351 bytes) sha 806bdda8ed6773d11f073b0eb77fc08fabf47fa0c1d84203a6a7f63fedc905fd (with 7 headers)
/main.css (gzip) 1/1 (299 bytes) sha b4879e7ba34e68b2965d626e48d772ce615e4f6b78b69cc8f2f91127ed18b850 (with 7 headers)
/main.css 1/1 (537 bytes) sha 75ac0c5aea719bb2b887fffbde61867be5c3a9eceab3d75619763c28735891cb (with 7 headers)
/index.js.map (gzip) 1/1 (156765 bytes) sha 59b0b2e1f6b269c82aa2719b756599ba5ad25fee2202cef4b616750aa51d4757 (with 7 headers)
/sample-asset.txt 1/1 (24 bytes) sha 2d523f5aaeb195da24dcff49b0d560a3d61b8af859cee78f4cff0428963929e6 (with 7 headers)
/index.html 1/1 (541 bytes) sha 87e0d04adb7292faf79bfea401d90d8142ad4f7a6bcbaef010be5597a84cae55 (with 7 headers)
/index.js (gzip) 1/1 (88420 bytes) sha 5205539336255e1c3c8b89c1553a6875d429f5012533a67ae038299aa5bc0fd4 (with 7 headers)
/favicon.ico 1/1 (15406 bytes) sha 4e8d31b50ffb59695389d94e393d299c5693405a12f6ccd08c31bcf9b58db2d4 (with 7 headers)
/index.js 1/1 (246807 bytes) sha 4ff1f3de2f730e260421224ab4e5f250b8241f92bba31eab3415fbbeed5e769a (with 7 headers)
Committing batch.
Deployed canisters.
URLs:
Frontend canister via browser
samples_frontend: https://cpsly-ryaaa-aaaak-aep7a-cai.ic0.app/
Backend canister via Candid interface:
samples_backend: https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.ic0.app/?id=cgrae-hqaaa-aaaak-aep6q-cai

Oh, now I see something… The call that shows 3T cycles was made to your local replica, not --network ic. No wonder it took the default amount.

I would expect --with-cycles 1 to produce this error the way it is coded. Canister creation costs 0.1T cycles, and we don’t want to use more cycles than the user specified, therefore if you specify --with-cycles 3000000000000 it will create a canister with 3T - 0.1T = 2.9T cycles. Trying to do this with only 1 cycle therefore fails

Your second attempt with 0.2T cycles worked, and I’d expect your canister to now have a bit less than 0.1T cycles left over

I could not understand.

The call that shows 3T cycles was made to your local replica, not --network ic.

–network ic is specified, but local replica ? On my local PC?

From your original message:

This (implicitly) targets --network local, and does not verify the result of dfx deploy --network ic. You would have to run dfx canister --network ic status --all instead

@Severin
Oh, it was a simple mistake. Thanks!