Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jgryffindor/7d4f48e63549abe5f072e6fe59ce15c3 to your computer and use it in GitHub Desktop.
Save jgryffindor/7d4f48e63549abe5f072e6fe59ce15c3 to your computer and use it in GitHub Desktop.
cosmovisor + POA + Software Upgrade + Group Proposal

Based on https://github.com/fmorency/cosmovisor-poa-test, with a twitst.

git clone https://github.com/liftedinit/manifest-ledger.git
cd manifest-ledger
git checkout v0.0.1-alpha.10
make build
./build/manifestd version
v0.0.1-alpha.10

Cleanup ~/.manifest (never do this in a production environment!)

rm -rf ~/.manifest

Initialize and configure the chain (never use --overwrite in a production environment!)

./build/manifestd init test --chain-id test --default-denom upoa --overwrite

./build/manifestd config set client chain-id test
./build/manifestd config set client keyring-backend test
./build/manifestd config set client broadcast-mode sync

Create the validation and self-delegate

# manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct
echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | ./build/manifestd keys add val --keyring-backend test --recover

 # staking
cat <<< $(jq '.app_state.staking.params.bond_denom = "upoa"' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json # PoA Token
cat <<< $(jq '.app_state.staking.params.min_commission_rate = "0.000000000000000000"' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json

# mint
cat <<< $(jq '.app_state.mint.params.mint_denom = "umfx"' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json # not used
cat <<< $(jq '.app_state.mint.params.blocks_per_year = "6311520"' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json

# Add the group and group policy that will act as the POA admin
cat <<< $(jq '.app_state.group.group_seq = "1"' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json
cat <<< $(jq '.app_state.group.groups = [{"id": "1", "admin": "manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj", "metadata": "AQ==", "version": "2", "total_weight": "2", "created_at": "2024-05-16T15:10:54.372190727Z"}]' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json
cat <<< $(jq '.app_state.group.group_members = [{"group_id": "1", "member": {"address": "manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct", "weight": "1", "metadata": "val", "added_at": "2024-05-16T15:10:54.372190727Z"}}, {"group_id": "1", "member": {"address": "manifest1efd63aw40lxf3n4mhf7dzhjkr453axurm6rp3z", "weight": "1", "metadata": "user2", "added_at": "2024-05-16T15:10:54.372190727Z"}}]' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json
cat <<< $(jq '.app_state.group.group_policy_seq = "1"' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json
cat <<< $(jq '.app_state.group.group_policies = [{"address": "manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj", "group_id": "1", "admin": "manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj", "metadata": "AQ==", "version": "2", "decision_policy": { "@type": "/cosmos.group.v1.ThresholdDecisionPolicy", "threshold": "1", "windows": {"voting_period": "30s", "min_execution_period": "0s"}}, "created_at": "2024-05-16T15:10:54.372190727Z"}]' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json

# Set the POA Admin to the Group policy address
cat <<< $(jq '.app_state.poa.params.admins = ["manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj"]' $HOME/.manifest/config/genesis.json) > $HOME/.manifest/config/genesis.json



./build/manifestd genesis add-genesis-account val 10000000upoa,1000000000umfx --keyring-backend test
./build/manifestd genesis gentx val 1000000upoa --chain-id test
./build/manifestd genesis collect-gentxs

Prepare Cosmovisor

export DAEMON_NAME=manifestd
export DAEMON_HOME=$HOME/.manifest
export DAEMON_ALLOW_DOWNLOAD_BINARIES=false
export DAEMON_RESTART_AFTER_UPGRADE=true
export POA_ADMIN_ADDRESS=manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj

Initialize and start Cosmovisor

cosmovisor init ./build/manifestd
cosmovisor run start

We now have a single validator node running! Let's now perform an upgrade.

Open a new terminal and change directory to the manifest-ledger repository.

Send some tokens to the group policy so it can execute group proposals.

./build/manifestd tx bank send manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj 100umfx --from val --yes --gas auto --gas-adjustment 1.3 --gas-prices 0.0011umfx 

Re-export the environment variables

export DAEMON_NAME=manifestd
export DAEMON_HOME=$HOME/.manifest
export DAEMON_ALLOW_DOWNLOAD_BINARIES=false
export DAEMON_RESTART_AFTER_UPGRADE=true
export POA_ADMIN_ADDRESS=manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj

Build the new version of the binary

git checkout v0.0.1-alpha.11
make build
./build/manifestd version
v0.0.1-alpha.11

Prepare the upgrade in cosmovisor

cosmovisor add-upgrade v0.0.1-alpha.11 ./build/manifestd

Create the software proposal.json group proposal

{
    "group_policy_address": "manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj",
    "messages": [
      {
        "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
        "authority": "manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj",
        "plan": {
          "name": "v0.0.1-alpha.11",
          "time": "0001-01-01T00:00:00Z",
          "height": "[UPGRADE_BLOCK_HEIGHT]",
          "info": "{}",
          "upgraded_client_state": null
        }
      }
    ],
    "metadata": "",
    "title": "Software upgrade",
    "summary": "This is a proposal to upgrade the software to v0.0.1-alpha.11",
    "proposers": ["manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct"]
}

Submit the group proposal

manifestd --home /data/manifest tx group submit-proposal v0.0.1-alpha.11.json --from manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct --yes --keyring-backend test --chain-id manifest-ledger-beta --gas auto --gas-adjustment 1.3 --gas-prices 0.0011umfx 

Note: Because we set the voting period to 30s, you will have 30s to vote on the proposal from the time the proposal is submitted. Go go go!

Verify the group proposal is active

manifestd --home /data/manifest q group proposals-by-group-policy manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj

Vote on the proposal

 manifestd --home /data/manifest tx group vote 1 manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct VOTE_OPTION_YES "" --gas auto --gas-adjustment 1.3 --gas-prices 0.0011umfx --keyring-backend test --chain-id manifest-ledger-beta

Wait for the voting period to pass

At this point, the proposal should have passed. You can verify the proposal status with

manifestd q group proposal 1

Execute the proposal

manifestd --home /data/manifest tx group exec 1 --from manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct --yes --gas auto --gas-adjustment 1.3 --gas-prices 0.0011umfx --keyring-backend test --chain-id manifest-ledger-beta

Check that the proposal was executed and that the software upgrade is scheduled

manifestd --home /data/manifest q upgrade plan
plan:
  height: "[SOME_HEIGHT]"
  info: '{}'
  name: v0.0.1-alpha.11
  time: "0001-01-01T00:00:00Z"

Wait until the chain reaches the software upgrade height and monitor Cosmovisor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment