Skip to content

Commit

Permalink
Install nns-dapp in dfx-stock-deploy (#412)
Browse files Browse the repository at this point in the history
# Motivation

`dfx nns install` installs an old version of nns-dapp. For the longest
time this has been good enough to use as a backend for local
development. The only thing it didn't support (AFAIK) was renaming
canisters.

But recent features import token and TVL require more recent
functionality from the backend so now an snsdemo snapshot can't be used
for nns-dapp frontend development without first installing the nns-dapp
canisters.

**NOTE:** bin/dfx-software-nns-dapp-install is modeled after
`bin/dfx-software-sns-aggregator-install` from which it is copied in the
first commit. So if you skip the first commit when reviewing, then you
only need to review the differences between them.

# Changes

1. Set canister ID of `nns-icp-index` in `bin/dfx-network-deploy`
because it isn't set by `dfx nns import` and is needed to pass in the
argument of `nns-dapp`.
2. Update the pinned release of nns-dapp to the newest proposal.
3. Add `bin/dfx-software-nns-dapp-install` to install nns-dapp.
4. Call `bin/dfx-software-nns-dapp-install` in `bin/dfx-stock-deploy`
after everything else is installed.

# Tested

Manually created a snapshot and used it with nns-dapp. TVL and import
token worked without upgrading nns-dapp.
  • Loading branch information
dskloetd authored Oct 14, 2024
1 parent 45b46f9 commit 9a53882
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/dfx-network-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if [[ "$DFX_NETWORK" == "local" ]]; then

dfx-nns-install --ic_commit "$DFX_IC_COMMIT"
dfx-nns-import --network "$DFX_NETWORK"
dfx-canister-set-id --canister_name nns-icp-index --canister_id q3fc5-haaaa-aaaaa-aaahq-cai
dfx-canister-set-id --canister_name nns-dapp --canister_id qsgjb-riaaa-aaaaa-aaaga-cai
dfx-canister-set-id --canister_name sns_aggregator --canister_id sgymv-uiaaa-aaaaa-aaaia-cai
dfx-canister-set-id --canister_name internet_identity --canister_id qhbym-qaaaa-aaaaa-aaafq-cai
Expand Down
100 changes: 100 additions & 0 deletions bin/dfx-software-nns-dapp-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
set -euo pipefail
SOURCE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
PATH="$SOURCE_DIR:$PATH"

print_help() {
cat <<-EOF
Fetches and installs the nns-dapp canister:
* Downloads the NNS dapp wasm.
* Adds the nns-dapp to dfx.json, if not already present.
* Deploys the downloaded wasm to the specified network.
EOF
}

# Source the clap.bash file ---------------------------------------------------
source "$SOURCE_DIR/clap.bash"
# Define options
clap.define short=n long=network desc="The dfx network to use" variable=DFX_NETWORK default="local"
clap.define short=r long=release desc="The release name" variable=DFX_RELEASE default="pinned"
clap.define short=m long=mode desc="The install mode: install, reinstall, upgrade" variable=DFX_MODE default="reinstall"
# Source the output file ----------------------------------------------------------
source "$(clap.build)"

: 'Convert aliases such as "pinned" into actual release names...'
DFX_RELEASE="$(dfx-software-nns-dapp-version "${DFX_RELEASE}")"

: 'Where to get the wasm from...'
WASM_URL="$(dfx-software-nns-dapp-ci-wasm-url --release "${DFX_RELEASE}")"

: 'Where to put the wasm...'
# Note: We do NOT clobber the wasm pointed to by dfx.json.
WASM_FILE="wasms/nns-dapp_${DFX_RELEASE}.wasm"

: 'Get the wasm if it is not already there.'
: 'We assume that releases are immutable, and the wasm filename contains the release and flavour.'
test -e "$WASM_FILE" || {
echo "Downloading wasm from: $WASM_URL"
mkdir -p "$(dirname "$WASM_FILE")"
curl --retry 5 --fail -sSL "${WASM_URL}" >"${WASM_FILE}.tmp"
mv "${WASM_FILE}.tmp" "${WASM_FILE}"
echo " saved wasm to: $WASM_FILE"
}

: 'We need at least a minimal entry in dfx.json'
jq -e '.canisters."nns-dapp"' dfx.json >/dev/null || {
echo "Adding nns-dapp to dfx.json..."
# TODO: Include API declaration .did files in release, so that we can get the candid.
jq -s '.[0] * .[1]' <(echo '{"canisters": { "nns-dapp": { "type": "custom", "candid": "candid/nns-dapp.did", "wasm": "'"${WASM_FILE}"'", "build": "true" }}}') dfx.json | sponge dfx.json
}

: "If the canister was remote, it isn't any more:"
DFX_NETWORK="$DFX_NETWORK" jq 'del(.canisters."nns-dapp".remote.id[env.DFX_NETWORK])' dfx.json | sponge dfx.json

canister_id() {
local canister_name="$1"
dfx canister id "$canister_name" --network "$DFX_NETWORK" || {
echo "Canister $canister_name not found on network $DFX_NETWORK." >&2
echo "not-found-canister-id"
}
}

# These args are specific to localhost. For other networks, the args should
# still work for nns-dapp to be used as a backend but if you want to load the
# frontend directly from the canister, you should upgrade nns-dapp with args
# created by `config.sh` from the nns-dapp repo.
CANISTER_ARG="(opt record{
args = vec {
record{ 0=\"API_HOST\"; 1=\"http://localhost:8080\" };
record{ 0=\"CKBTC_INDEX_CANISTER_ID\"; 1=\"$(canister_id ckbtc_index)\" };
record{ 0=\"CKBTC_LEDGER_CANISTER_ID\"; 1=\"$(canister_id ckbtc_ledger)\" };
record{ 0=\"CKBTC_MINTER_CANISTER_ID\"; 1=\"$(canister_id ckbtc_minter)\" };
record{ 0=\"CKETH_INDEX_CANISTER_ID\"; 1=\"$(canister_id cketh_index)\" };
record{ 0=\"CKETH_LEDGER_CANISTER_ID\"; 1=\"$(canister_id cketh_ledger)\" };
record{ 0=\"CKUSDC_INDEX_CANISTER_ID\"; 1=\"$(canister_id ckusdc_index)\" };
record{ 0=\"CKUSDC_LEDGER_CANISTER_ID\"; 1=\"$(canister_id ckusdc_ledger)\" };
record{ 0=\"CYCLES_MINTING_CANISTER_ID\"; 1=\"$(canister_id nns-cycles-minting)\" };
record{ 0=\"DFX_NETWORK\"; 1=\"$DFX_NETWORK\" };
record{ 0=\"FEATURE_FLAGS\"; 1=\"{\\\"ENABLE_CKBTC\\\":true,\\\"ENABLE_CKTESTBTC\\\":false}\" };
record{ 0=\"FETCH_ROOT_KEY\"; 1=\"true\" };
record{ 0=\"GOVERNANCE_CANISTER_ID\"; 1=\"$(canister_id nns-governance)\" };
record{ 0=\"HOST\"; 1=\"http://localhost:8080\" };
record{ 0=\"IDENTITY_SERVICE_URL\"; 1=\"http://$(canister_id internet_identity).localhost:8080\" };
record{ 0=\"INDEX_CANISTER_ID\"; 1=\"$(canister_id nns-icp-index)\" };
record{ 0=\"LEDGER_CANISTER_ID\"; 1=\"$(canister_id nns-ledger)\" };
record{ 0=\"OWN_CANISTER_ID\"; 1=\"$(canister_id nns-dapp)\" };
record{ 0=\"ROBOTS\"; 1=\"<meta name=\\\"robots\\\" content=\\\"noindex, nofollow\\\" />\" };
record{ 0=\"SNS_AGGREGATOR_URL\"; 1=\"http://$(canister_id sns_aggregator).localhost:8080\" };
record{ 0=\"STATIC_HOST\"; 1=\"http://localhost:8080\" };
record{ 0=\"TVL_CANISTER_ID\"; 1=\"$(canister_id nns-dapp)\" };
record{ 0=\"WASM_CANISTER_ID\"; 1=\"$(canister_id nns-sns-wasm)\" };
};
})"

echo "Installing nns-dapp..."
# Note: We specify the wasm file explicitly as an existing wasm path may not point to the requested wasm.
dfx canister install nns-dapp --wasm "$WASM_FILE" --upgrade-unchanged --mode "$DFX_MODE" --yes --network "${DFX_NETWORK}" --argument "$CANISTER_ARG"
echo "Checking nns-dapp installation..."
dfx-canister-check-wasm-hash --canister nns-dapp --network "$DFX_NETWORK" --wasm "${WASM_FILE}"
echo "Finished installing nns-dapp. Enjoy!"
3 changes: 3 additions & 0 deletions bin/dfx-stock-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ dfx canister call cketh_ledger icrc1_transfer "(record {to=record{owner=principa
dfx canister call ckusdc_ledger icrc1_transfer "(record {to=record{owner=principal \"$FAUCET_ADDRESS\"}; amount=10_000_000_000_000:nat})"
dfx canister call ckred_ledger icrc1_transfer "(record {to=record{owner=principal \"$FAUCET_ADDRESS\"}; amount=10_000_000_000_000:nat})"

# Install nns-dapp last so all the canister IDs exist to pass as args.
dfx-software-nns-dapp-install --network "$DFX_NETWORK" --release pinned

: Add the nns root as a controller to the frontend canisters
NNS_ROOT="$(dfx canister id nns-root --network "$DFX_NETWORK")"
for canister in nns-dapp internet_identity; do
Expand Down
2 changes: 1 addition & 1 deletion bin/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SNS_AGGREGATOR_RELEASE=proposal-129614-agg
DFX_IC_COMMIT=094f99d173b860132c711bebdf4833f951e772d4
INTERNET_IDENTITY_RELEASE=release-2023-10-27
NNS_DAPP_RELEASE=proposal-121690
NNS_DAPP_RELEASE=proposal-133373
DIDC_VERSION=2023-07-25
QUILL_VERSION=0.4.0
IDL2JSON_VERSION=0.8.5
Expand Down

0 comments on commit 9a53882

Please sign in to comment.