From d152e7e17b3d9240afed38249cb0a0e5424cfc85 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Fri, 29 Mar 2024 10:37:52 +0700 Subject: [PATCH] add upgrade handler --- .gitignore | 3 +- .idea/.gitignore | 8 +++ .idea/composable-cosmos.iml | 9 ++++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ app/app.go | 3 +- app/upgrades/v6_5_0/upgrade.go | 16 +++--- app/upgrades/v7_0_0/constants.go | 20 +++++++ app/upgrades/v7_0_0/upgrade.go | 24 +++++++++ scripts/localnode.sh | 92 ++++++++++++++++++++++++++++++++ scripts/test-upgrade.sh | 14 ++--- 11 files changed, 186 insertions(+), 17 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/composable-cosmos.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 app/upgrades/v7_0_0/constants.go create mode 100644 app/upgrades/v7_0_0/upgrade.go create mode 100644 scripts/localnode.sh diff --git a/.gitignore b/.gitignore index 014203a48..e31ef07c1 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,5 @@ go.work.sum _build -screenlog.0 \ No newline at end of file +screenlog.0 +mytestnet \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/composable-cosmos.iml b/.idea/composable-cosmos.iml new file mode 100644 index 000000000..5e764c4f0 --- /dev/null +++ b/.idea/composable-cosmos.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..612c5a16e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/app.go b/app/app.go index db469dfa5..b44dc63f9 100644 --- a/app/app.go +++ b/app/app.go @@ -39,6 +39,7 @@ import ( "github.com/notional-labs/composable/v6/app/keepers" "github.com/notional-labs/composable/v6/app/upgrades/v6_5_0" + "github.com/notional-labs/composable/v6/app/upgrades/v7_0_0" // bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "cosmossdk.io/x/evidence" @@ -144,7 +145,7 @@ var ( // https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34 EnableSpecificProposals = "" - Upgrades = []upgrades.Upgrade{v6_5_0.Upgrade} + Upgrades = []upgrades.Upgrade{v6_5_0.Upgrade, v7_0_0.Upgrade} Forks = []upgrades.Fork{} ) diff --git a/app/upgrades/v6_5_0/upgrade.go b/app/upgrades/v6_5_0/upgrade.go index 49b559482..92ea1d655 100644 --- a/app/upgrades/v6_5_0/upgrade.go +++ b/app/upgrades/v6_5_0/upgrade.go @@ -27,14 +27,14 @@ func CreateUpgradeHandler( keepers.IbcTransferMiddlewareKeeper.SetParams(sdkctx, custommiddlewareparams.Params) // remove broken proposals - BrokenProposals := [3]uint64{2, 6, 11} - for _, proposal_id := range BrokenProposals { - _, err := keepers.GovKeeper.Proposals.Get(sdkctx, proposal_id) - if err != nil { - keepers.GovKeeper.DeleteProposal(sdkctx, proposal_id) - } - - } + //BrokenProposals := [3]uint64{2, 6, 11} + //for _, proposal_id := range BrokenProposals { + // _, err := keepers.GovKeeper.Proposals.Get(sdkctx, proposal_id) + // if err != nil { + // keepers.GovKeeper.DeleteProposal(sdkctx, proposal_id) + // } + // + //} // burn extra ppica in escrow account // this ppica is unused because it is a native token stored in escrow account diff --git a/app/upgrades/v7_0_0/constants.go b/app/upgrades/v7_0_0/constants.go new file mode 100644 index 000000000..5fc043e6c --- /dev/null +++ b/app/upgrades/v7_0_0/constants.go @@ -0,0 +1,20 @@ +package v7_0_0 + +import ( + store "cosmossdk.io/store/types" + "github.com/notional-labs/composable/v6/app/upgrades" +) + +const ( + // UpgradeName defines the on-chain upgrade name for the composable upgrade. + UpgradeName = "v7_0_0" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{}, + Deleted: []string{"alliance"}, + }, +} diff --git a/app/upgrades/v7_0_0/upgrade.go b/app/upgrades/v7_0_0/upgrade.go new file mode 100644 index 000000000..6f081c350 --- /dev/null +++ b/app/upgrades/v7_0_0/upgrade.go @@ -0,0 +1,24 @@ +package v7_0_0 + +import ( + "context" + + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/notional-labs/composable/v6/app/keepers" + "github.com/notional-labs/composable/v6/app/upgrades" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + _ upgrades.BaseAppParamManager, + _ codec.Codec, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/scripts/localnode.sh b/scripts/localnode.sh new file mode 100644 index 000000000..d556d25cc --- /dev/null +++ b/scripts/localnode.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +echo "starting localnode" + +BINARY=$1 +CONTINUE=${CONTINUE:-"false"} +HOME_DIR=mytestnet +ENV=${ENV:-""} + +if [ "$CONTINUE" == "true" ]; then + echo "\n ->> continuing from previous state" + $BINARY start --home $HOME_DIR --log_level debug + exit 0 +fi + +rm -rf mytestnet +pkill centaurid + +# check DENOM is set. If not, set to upica +DENOM=${2:-upica} +echo "denom: $DENOM" +COMMISSION_RATE=0.01 +COMMISSION_MAX_RATE=0.02 + +SED_BINARY=sed +# check if this is OS X +if [[ "$OSTYPE" == "darwin"* ]]; then + # check if gsed is installed + if ! command -v gsed &> /dev/null + then + echo "gsed could not be found. Please install it with 'brew install gnu-sed'" + exit + else + SED_BINARY=gsed + fi +fi + +# check BINARY is set. If not, build centaurid and set BINARY +if [ -z "$BINARY" ]; then + make build + BINARY=build/centaurid +fi + +CHAIN_ID="localpica" +KEYRING="test" +KEY="test0" +KEY1="test1" +KEY2="test2" + +# Function updates the config based on a jq argument as a string +update_test_genesis () { + # update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"' + cat $HOME_DIR/config/genesis.json | jq "$1" > $HOME_DIR/config/tmp_genesis.json && mv $HOME_DIR/config/tmp_genesis.json $HOME_DIR/config/genesis.json +} + +$BINARY init --chain-id $CHAIN_ID moniker --home $HOME_DIR + +$BINARY keys add $KEY --keyring-backend $KEYRING --home $HOME_DIR +$BINARY keys add $KEY1 --keyring-backend $KEYRING --home $HOME_DIR +$BINARY keys add $KEY2 --keyring-backend $KEYRING --home $HOME_DIR + +# Allocate genesis accounts (cosmos formatted addresses) +$BINARY add-genesis-account $KEY "1000000000000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR +$BINARY add-genesis-account $KEY1 "1000000000000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR +$BINARY add-genesis-account $KEY2 "1000000000000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR + +update_test_genesis '.app_state["gov"]["params"]["voting_period"]="5s"' +update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' +update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1000000"}]' +update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}' +update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' + +# enable rest server and swagger +$SED_BINARY -i '0,/enable = false/s//enable = true/' $HOME_DIR/config/app.toml +$SED_BINARY -i 's/swagger = false/swagger = true/' $HOME_DIR/config/app.toml +$SED_BINARY -i -e 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' $HOME_DIR/config/app.toml +$SED_BINARY -i 's/minimum-gas-prices = "0.25upica"/minimum-gas-prices = "0.0upica"/' $HOME_DIR/config/app.toml + +## Adjust block time +$SED_BINARY -i 's/timeout_commit = "5s"/timeout_commit = "500ms"/' $HOME_DIR/config/config.toml + + + +# Sign genesis transaction +$BINARY gentx $KEY "1000000000000000000000${DENOM}" --commission-rate=$COMMISSION_RATE --commission-max-rate=$COMMISSION_MAX_RATE --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME_DIR + +# Collect genesis tx +$BINARY collect-gentxs --home $HOME_DIR + +# Run this to ensure everything worked and that the genesis file is setup correctly +$BINARY validate-genesis --home $HOME_DIR +$BINARY start --home $HOME_DIR diff --git a/scripts/test-upgrade.sh b/scripts/test-upgrade.sh index e95ce3001..05cd2da2b 100755 --- a/scripts/test-upgrade.sh +++ b/scripts/test-upgrade.sh @@ -39,7 +39,7 @@ if [ $# -eq 1 ] && [ $1 == "--reinstall-old" ] || ! command -v _build/old/centau fi # install new binary -if ! command -v _build/new/picad &> /dev/null +if ! command -v _build/new/centaurid &> /dev/null then mkdir -p _build/new GOBIN="$ROOT/_build/new" go install -mod=readonly ./... @@ -96,12 +96,12 @@ run_upgrade () { UPGRADE_HEIGHT=$((STATUS_INFO[1] + 20)) echo "UPGRADE_HEIGHT = $UPGRADE_HEIGHT" - tar -cf ./_build/new/picad.tar -C ./_build/new picad - SUM=$(shasum -a 256 ./_build/new/picad.tar | cut -d ' ' -f1) + tar -cf ./_build/new/centaurid.tar -C ./_build/new centaurid + SUM=$(shasum -a 256 ./_build/new/centaurid.tar | cut -d ' ' -f1) UPGRADE_INFO=$(jq -n ' { "binaries": { - "linux/amd64": "file://'$(pwd)'/_build/new/picad.tar?checksum=sha256:'"$SUM"'", + "linux/amd64": "file://'$(pwd)'/_build/new/centaurid.tar?checksum=sha256:'"$SUM"'", } }') @@ -151,9 +151,9 @@ sleep 1 # run new node echo -e "\n\n=> =>continue running nodes after upgrade" if [[ "$OSTYPE" == "darwin"* ]]; then - CONTINUE="true" screen -L -dmS picad bash scripts/localnode.sh _build/new/picad $DENOM + CONTINUE="true" screen -L -dmS centaurid bash scripts/localnode.sh _build/new/centaurid $DENOM else - CONTINUE="true" screen -L -dmS picad bash scripts/localnode.sh _build/new/picad $DENOM + CONTINUE="true" screen -L -dmS centaurid bash scripts/localnode.sh _build/new/centaurid $DENOM fi sleep 5 @@ -167,7 +167,7 @@ if [ ! -z "$ADDITIONAL_AFTER_SCRIPTS" ]; then # check if SCRIPT is a file if [ -f "$SCRIPT" ]; then echo "executing additional after scripts from $SCRIPT" - source $SCRIPT _build/new/picad + source $SCRIPT _build/new/centaurid sleep 5 else echo "$SCRIPT is not a file"