Upgrading canisters - what happens to a spawned child canister?

If I have a canister that spawns child canisters, and I want to upgrade the code on either the parent or child canisters:

  1. If I upgrade the parent canister, what happens to the existing child canisters? Do they get upgraded too?
  2. If I find the principles of the created child canisters and I want to upgrade them directly, how would I do that?
1 Like

When a parent canister creates a child, the parent becomes a controller of spawned childs. When you create a canister manually through dfx, then you become a controller.
Only the controller can upgrade the code.
In your case:

  • No. Child canisters will not upgrade their code automatically
  • If you want to do this, write code to the parent canister’s post-upgrade hook. That code should find all child canisters and calls the install_code method with some .wasm file.
  • Or create an similar update-method on the parent canister and call it yourself after parent upgrade
1 Like

Only that you can’t do calls from canister_postupgrade, so you will have to implement that as a separate step, i.e. the third variant.

2 Likes

Sorry, I didn’t know that, thanks :slight_smile:

@nomeata

When I build the parent canister, I only get a wasm file for the parent canister, so I can’t call install_code since there is no separate child wasm generated. (Although I do see the calls listed in the parent wasm) So I’m wondering maybe if there’s a get the updated wasm_module blob of the child canister during the upgrade process? Or a way to extract the child wasm blob out of the final wasm and upgrade manually?

Motoko doesn’t yet provide all the necessary hooks. @claudio has maybe thought the most about this.

1 Like

Ok thanks Joachim, I’ll keep an eye out for updates on that