Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a command to update SNS asset canister. #242

Open
ClankPan opened this issue Sep 10, 2024 · 1 comment
Open

Adding a command to update SNS asset canister. #242

ClankPan opened this issue Sep 10, 2024 · 1 comment

Comments

@ClankPan
Copy link

ClankPan commented Sep 10, 2024

Outline

This issue proposes adding a command to submit a commit-proposed-batch-proposal directly using evidence in hex format, eliminating the need to manually calculate the payload.

Once a custom function for committing to the proposed batch of the SNS asset canister is registered, candid data needs to be passed into the ExecuteGenericNervousSystemFunction payload as a blob. However, handling this in bash is quite tricky.

Currently, users receive evidence in hex format via --by-proposal, but the asset canister's commit_proposed_batch method requires the evidence in blob format. It then needs to be converted back into blob format again before passing it into the payload. This process is overly complex and prone to errors.

I added the command in my fork at this branch

What else do I need to do to submit a PR?

Test Flow

Setup Repositry

  1. Clone repositries

    mkdir test_commit_proposed_batch_command
    cd test_commit_proposed_batch_command
    export ROOT=$(pwd)
    git clone https://github.com/ClankPan/quill
    git clone https://github.com/dfinity/sns-testing.git
    dfx new --type rust test_dapp

Run Local SNS

  1. Move to sns-testing repositry.

    cd $ROOT
    cd sns-testing
  2. Open another terminal tab and run basic scenario of sns-tesgint repo with following https://github.com/dfinity/sns-testing?tab=readme-ov-file#special-instructions-for-apple-silicon-users.

  3. Set sns governance canister.

    export SNS_GOV=$(jq -r '.governance_canister_id' ./sns_canister_ids.json)

Deploy Asset Canister and Grant Permission

  1. Deploy asset canister and set permisson and make update proposal.

    cd $ROOT
    cd test_dapp
    dfx deploy
    dfx canister call test_dapp_frontend grant_permission "(record {permission = variant {Commit}; to_principal = principal \"${SNS_GOV}\"})"
    export ASSET_ID=$(dfx canister id test_dapp_frontend)
    dfx deploy test_dapp_frontend --upgrade-unchanged --by-proposal

Register Commit Function

  1. Create a file to register custom function as register_commit_func.sh in sns-testing.

    #!/usr/bin/env bash
    
    set -euo pipefail
    
    cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
    
    . ./constants.sh normal
    
    export DEVELOPER_NEURON_ID="$(dfx canister \
      --network "${NETWORK}" \
      call "${SNS_GOVERNANCE_CANISTER_ID}" \
      list_neurons "(record {of_principal = opt principal\"${DX_PRINCIPAL}\"; limit = 1})" \
          | idl2json \
          | jq -r ".neurons[0].id[0].id" \
          | python3 -c "import sys; ints=sys.stdin.readlines(); sys.stdout.write(bytearray(eval(''.join(ints))).hex())")"
    
    echo $DEVELOPER_NEURON_ID
    
    export CID="${ASSET_ID}"
    export FUNC_ID="1007"
    quill sns  \
      --canister-ids-file ./sns_canister_ids.json  \
      --pem-file "${PEM_FILE}"  \
      make-proposal --proposal "(record { title=\"\"; url=\"\"; summary=\"\"; action=opt variant {AddGenericNervousSystemFunction = record {id=${FUNC_ID}:nat64; name=\"commit\"; description=\"\"; function_type=opt variant {GenericNervousSystemFunction=record{validator_canister_id=opt principal\"$CID\"; target_canister_id=opt principal\"$CID\"; validator_method_name=opt\"validate_commit_proposed_batch\"; target_method_name=opt\"commit_proposed_batch\"}}}}})" $DEVELOPER_NEURON_ID > msg.json
    quill --insecure-local-dev-mode send --yes msg.json
  2. Register new GenericNervousSystemFunction that commit proposed batch of asset canister.

    cd $ROOT
    cd sns-testing
    ./register_commit_func.sh
    ./vote_on_sns_proposal.sh 61 3 y

Build Quill

  1. Build quill with the new command added and copy it in sns-testing/bin/

    cd $ROOT
    cd quill
    git checkout custom_command
    cargo build --release
    cp ./target/release/quill ../sns-testing/bin/quill

Test new command

  1. Crate a file to test the commit_proposed_batch_command as test_commit_command.sh in sns-testing.

    #!/usr/bin/env bash
    
    set -euo pipefail
    
    cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
    
    . ./constants.sh normal
    
    export DEVELOPER_NEURON_ID="$(dfx canister \
      --network "${NETWORK}" \
      call "${SNS_GOVERNANCE_CANISTER_ID}" \
      list_neurons "(record {of_principal = opt principal\"${DX_PRINCIPAL}\"; limit = 1})" \
          | idl2json \
          | jq -r ".neurons[0].id[0].id" \
          | python3 -c "import sys; ints=sys.stdin.readlines(); sys.stdout.write(bytearray(eval(''.join(ints))).hex())")"
    
    echo $DEVELOPER_NEURON_ID
    export FUNC_ID="1007"
    
    bin/quill sns   \
      --canister-ids-file ./sns_canister_ids.json  \
      --pem-file ~/.config/dfx/identity/$(dfx identity whoami)/identity.pem  \
      make-commit-proposed-batch-proposal \
      --title "" \
      --url  "" \
      --summary "" \
      --function-id "${FUNC_ID}"  \
      --batch-id 2  \
      --evidence e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855   \
      $DEVELOPER_NEURON_ID > msg.json
    bin/quill --insecure-local-dev-mode send --yes msg.json
  2. Test the new command.

    cd $ROOT
    cd sns-testing
    ./test_commit_command.sh
    ./vote_on_sns_proposal.sh 61 4 y
@ClankPan
Copy link
Author

I crated a PR #243 for this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant