dfinity / dfinity/quill

Adding a command to update SNS asset canister.

Open
#242 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
84
Forks
30
Avg merge
23h 49m
Merged PRs (30d)
1

Description

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
    

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the custom_command branch linked in the issue and compare its new command with the existing SNS proposal commands. Reproduce the documented flow using register_commit_func.sh and test_commit_command.sh, then confirm the command handles the hex evidence and produces a proposal that passes the listed SNS voting steps.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.