Cross-canister compatible Post-Init hook

I saw many canisters that must do some initialization logic before answering update calls. For example:

  • The II canister needs to initialize its random seed before creating anchors.
  • The ckBTC minter canister must obtain its ECDSA pubkey before answering any calls.

The common solution so far is to add an initialization guard to every update call:

#[update]
async fn mint(args: Args) -> Result {
  init().await;
  // ...
}

However, adding a proper post-init hook is technically tricky because it must complete before the first “real” message arrives. If we don’t ensure this, the usefulness of the post-init hook is minimal: we must contaminate all update calls with checks in case the first message arrives before the initialization completes.

One promising solution is introducing another canister state, “initializing”. The replica could automatically reject (or buffer) all incoming messages until the initialization completes. This feature will be helpful, but it would be quite a chunk of work for the execution team.

7 Likes