dfinity / sdk

IC SDK: a Software Development Kit for creating and managing canister smart contracts on the ICP blockchain.

Home Page:https://internetcomputer.org/developers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

clean initial build of a canister importing nns-ledger installed by dfx nns fails and then succeeds if deployed once again

atengberg opened this issue · comments

dfx version: 0.12.1
assumes networks.json has been setup correctly

Steps to recreate:

dfx new demo
dfx start --clean --background
dfx nns install
dfx nns import 
  • edit dfx.json to include imported "nns-ledger" as dependency to demo_backend
  • edit src/demo_backend/main.mo to include line the
    import Ledger "canister:nns-ledger";

now anytime the following is run again

dfx stop
dfx start --clean --background
dfx nns install

followed by either of the following

dfx canister create demo_backend
dfx build demo_backend
//or
dfx deploy demo_backend

it will always produce the following output/error

Creating a wallet canister on the local network.
The wallet canister on the "local" network for user "default" is <a principal>
Deploying: demo_backend
Creating canisters...
Creating canister demo_backend...
demo_backend canister created with canister id: <the same principal>
Building canisters...
WARN: Failed to copy canister candid from ~/demo/candid/nns-ledger.did to ~/demo/.dfx/local/canisters/idl/ryjl3-tyaaa-aaaaa-aaaba-cai.did. This may produce errors during the build.
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
  Failed to build call canisters.
    Failed while trying to build all canisters.
      The build step failed for canister '<the same pricipal>' (demo_backend) with an embedded error: Failed to build Motoko canister 'demo_backend'.: Failed to compile Motoko.: Failed to run 'moc'.: The command '"~/.cache/dfinity/versions/0.12.1/moc" "~/demo/src/demo_backend/main.mo" "-o" "~/demo/.dfx/local/canisters/demo_backend/demo_backend.wasm" "-c" "--debug" "--idl" "--stable-types" "--public-metadata" "candid:service" "--actor-idl" "~/demo/.dfx/local/canisters/idl/" "--actor-alias" "demo_backend" "<the same principal>" "--actor-alias" "nns-ledger" "ryjl3-tyaaa-aaaaa-aaaba-cai" "--package" "base" "~/.cache/dfinity/versions/0.12.1/base"' failed with exit status 'exit status: 1'.
Stdout:

Stderr:
~/demo/src/demo_backend/main.mo:1.1-1.36: import error [M0009], file "~/demo/.dfx/local/canisters/idl/ryjl3-tyaaa-aaaaa-aaaba-cai.did" does not exist

however running deploy once again will successfully deploy the canister

dfx deploy demo_backend

and now any calls from the demo_backend's code calling on the Ledger import will work as expected

Also the Motoko VS code extension (v0.7.2) persists to highlight the import line as an error in demo_backend.mo

Thank you for this bug report, Ashton! I can reproduce the bug locally, and have it added to our own backlog.

I suggest since the workaround is so simple (just rerun the command) we won't treat this as high priority, but we'll get to it eventually.

This is probably related to my changes made in #2687, which at least made it possible for this bug to appear. Maybe the bug was also introduced in that PR.

Thank you for the detailed repro steps. This appears to be fixed in dfx 0.15.1. I followed the steps above with both of these variants, but in both cases the build or deploy succeeded.

  • dfx canister create demo_backend && dfx canister build demo_backend
  • dfx deploy demo_backend
Deployed canisters.
URLs:
  Backend canister via Candid interface:
    demo_backend: http://127.0.0.1:8080/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=bkyz2-fmaaa-aaaaa-qaaaq-cai
$ find .dfx -name '*.did'
.dfx/local/canisters/idl/ryjl3-tyaaa-aaaaa-aaaba-cai.did
.dfx/local/canisters/demo_backend/service.did
.dfx/local/canisters/demo_backend/demo_backend.did
.dfx/local/canisters/demo_backend/constructor.did
.dfx/local/lsp/bkyz2-fmaaa-aaaaa-qaaaq-cai.did

I tried to repro with dfx 0.12.1 (to make sure I was following the repro steps properly), but it seems that the resources that dfx nns install for dfx 0.12.1 depends no longer exist or are no longer accessible:

$ dfx nns install
Found local replica running on port 56269
Checking out the environment...
Found local replica running on port 56269
Installing the core backend wasm canisters...
Downloading /Users/ericswanson/.cache/dfinity/versions/0.12.1/wasms/registry-canister.wasm
  from .gz: https://download.dfinity.systems/ic/dcbf401f27d9b48354e68389c6d8293c4233b055/canisters/registry-canister.wasm.gz
Error: Failed to install NNS components.
Caused by: Failed to install NNS components.
  Failed to download NNS wasm files.
    Failed to download registry-canister.wasm from the IC CI.
      Failed to download and unzip '"/Users/ericswanson/.cache/dfinity/versions/0.12.1/wasms/registry-canister.wasm"' from '"https://download.dfinity.systems/ic/dcbf401f27d9b48354e68389c6d8293c4233b055/canisters/registry-canister.wasm.gz"'.
        Failed to unzip WASM to '/Users/ericswanson/.cache/dfinity/versions/0.12.1/wasms/.tmpQZvM9T/wasm'
          invalid gzip header
$ curl "https://download.dfinity.systems/ic/dcbf401f27d9b48354e68389c6d8293c4233b055/canisters/registry-canister.wasm.gz"
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>QDGG8BYYB5YC1RES</RequestId><HostId>YhhDrvShkwZzRkO7PmgTw6G2RsoZzoo0woI80WpBBoXgfKKosNBJ82oHnupXec/7gHzRRyNYCBEBuV17W+Mu3Q==</HostId></Error>

I also tried with dfx 0.14.4, but it failed in a different way:

/Users/.../0.14.4/demo/src/demo_backend/main.mo:1.1-1.36: import error [M0153], file /Users/.../0.14.4/demo/.dfx/local/canisters/idl/ryjl3-tyaaa-aaaaa-aaaba-cai.did uses Candid types without corresponding Motoko type
ryjl3-tyaaa-aaaaa-aaaba-cai.did:357.10-402.2: import error [M0163], cannot import a Candid service constructor

Relevant parts of the project to verify that I understood the repro steps correctly:

$ head -n 7 dfx.json
{
  "canisters": {
    "demo_backend": {
      "main": "src/demo_backend/main.mo",
      "type": "motoko",
      "dependencies": [ "nns-ledger" ]
    },
$ head -3 src/demo_backend/main.mo 
import Ledger "canister:nns-ledger";
actor {
  public query func greet(name : Text) : async Text {

@atengberg Would you please retry the above with dfx 0.15.1 and let me know how it goes?

Closing as I cannot reproduce this in more recent dfx releases.

Apologies for the delay in a reply. It's been sometime--great to see such such improvements being made. Confirmed for dfx version 0.17.0 and dfx nns installed as an extension, this is not only an not an issue anymore (as you've already determined), but with the helpful command line prompts, easier to get immediately setup and working. Really great to see all the progress being made!