CMC functional deploy arguments

I’m facing the error No subnets in which to create a canister. when attempting to create a canister with the CMC I deployed locally. I suspect I didn’t deploy it with the appropriate parameters.

What are the expected parameters to deploy a functional CMC locally?

Those are the one I use.

And those are the parameters I use to call create_canister on the CMC:

let create_canister_arg = CreateCanister {
        subnet_type: None,
        subnet_selection: None,
        settings: Some(CanisterSettings {
            controllers: Some(controllers.clone()),
            compute_allocation: None,
            memory_allocation: None,
            freezing_threshold: None,
            reserved_cycles_limit: None,
            log_visibility: None,
            wasm_memory_limit: Some(Nat::from(WASM_MEMORY_LIMIT)),
        }),
    };

Give that I pass no selection, I’m landing I guess in the automatic selection of the subnet related to the caller, therefore assuming something wrong in the configuration.

I guess it misses, at least, @bitdivine one year old answers.

and

What the heck are the arguments for the proposal function ID 14 (SetAuthorizedSubnetworks)?

I’ve been trying for an hour or more to replicate what I found in the source code of the CMC and I always end facing deserialization error when the proposal is executed.

juno-console-1 | 2024-10-13 13:24:00.192752384 UTC: [Canister rrkah-fqaaa-aaaaa-aaaaq-cai] [Governance] Execution of proposal: 1 failed. Reason: GovernanceError { error_type: External, error_message: "Error executing ExecuteNnsFunction proposal. Rejection message: IC0503: Error from Canister rkp4c-7iaaa-aaaaa-aaaca-cai: Canister called ic0.trap with message: Panicked at ‘Deserialization Failed: "Fail to decode argument 0 from table2 to record { who : opt principal; subnets : vec principal }"’, rs/rust_canisters/dfn_core/src/endpoint.rs:33:41.\nConsider gracefully handling failures from this canister or altering the canister to handle exceptions.

That’s my code:


export const makeAuthorizedSubnetworksProposal = async ({
  identities
}: Pick<ModuleInstallParams, 'identities'>) => {
  const {[MAIN_IDENTITY_KEY]: identity} = identities;

  const agent = await createAgent({
    identity,
    host: 'http://127.0.0.1:5987',
    fetchRootKey: true
  });

  const {makeProposal} = GovernanceCanister.create({
    agent
  });

  const subnetId = Principal.fromUint8Array(arrayBufferToUint8Array(agent.rootKey));

  const arg = IDL.encode(
    [
      IDL.Record({
        who: IDL.Opt(IDL.Principal),
        subnets: IDL.Vec(IDL.Principal)
      })
    ],
    [
      {
        who: [],
        subnets:[subnetId]
      }
    ]
  );

  const request: MakeProposalRequest = {
    neuronId: BigInt(NEURON_ID),
    url: 'https://forum.dfinity.org',
    title: 'Authorize CMC to create canisters in subnets',
    summary: 'The lack of documentation makes developing anything with the CMC canister a pain.',
    action: {
      ExecuteNnsFunction: {
        nnsFunctionId: NnsFunction.SetAuthorizedSubnetworks,
        payloadBytes: arg
      }
    }
  };

  await makeProposal(request);
};

The source code of the CMC diverges from the registry source code where subnets become optional but, setting it as such does not help. When I do so

const arg = IDL.encode(
    [
      IDL.Record({
        who: IDL.Opt(IDL.Principal),
        subnets: IDL.Opt(IDL.Vec(IDL.Principal))
      })
    ],
    [
      {
        who: [],
        subnets: [[subnetId]]
      }
    ]
  );

It fails on another table

juno-console-1 | 2024-10-13 13:33:58.349724925 UTC: [Canister rkp4c-7iaaa-aaaaa-aaaca-cai] Panicked at ‘Deserialization Failed: “Fail to decode argument 0 from table3 to record { who : opt principal; subnets : vec principal }”’, rs/rust_canisters/dfn_core/src/endpoint.rs:33:41

Got it!

juno-console-1 | 2024-10-13 13:38:06.454728512 UTC: [Canister rkp4c-7iaaa-aaaaa-aaaca-cai] [cycles] setting default subnet list

The subnets definition as in the source code of the CMC is correct but, the issue was the subnet ID which was encoded to an invalid principal (never saw that before).

juno-console-1 | ------------------------> SUBNET_ID: w3ivr-5rqqg-bdahi-gbuvq-maiea-gbny7-afama-qeaig-bqvqm-aieag-bny7a-famba-ca3ba-c22pn-7d23i-arini-uzkox-l7ei2-6ys6q-qt4x7-t5yfr-g2zze-h5cl5-6sjjg-ihmli-qhsgn-c6czw-mdten-2lqz5-ssihq-3m3kq-4lx3q-nxogr-57h4w-bcfzu-xpygi-etgrj-euood-cfhzk-a6rbx-wy5ih-2bgib-inldp-qbzqa

Once I fixed the usage with Principal.selfAuthenticating then the proposal was executed, it seems.

juno-console-1 | ------------------> SUBNET_ID jj7r5-c2tzc-6ns5v-wjfpq-auetr-de3ew-7a7hb-znr7x-s767e-am7mv-5qe

Finally, it worked out. Gosh.

Thanks @bitdivine the solution a long time ago!

Implemented in Juno Docker: