From afbc54b8c70280bcb411b768a42cc1d70815e1f1 Mon Sep 17 00:00:00 2001 From: Kien Date: Tue, 2 Apr 2024 16:54:14 +0700 Subject: [PATCH] Kien/setup test upgrade 08 wasms (#19) * feat: add env package * test: update localnode scripts * feat: running old node * feat: scripts to run old node * feat: run preupgrade * perf: tweak blocktime, and run upgrade * test: migrate 08 wasm data * feat: check if code exist --- Makefile | 14 +- app/ibctesting/endpoint.go | 3 +- app/ibctesting/path.go | 2 +- app/ibctesting/simapp/export.go | 12 +- app/ibctesting/wasm.go | 23 +-- go.mod | 1 + scripts/localnode.sh | 92 +++++------- scripts/old-node/push-08-wasm.sh | 14 ++ scripts/old-node/testnode.sh | 71 +++++++++ scripts/testnode.sh | 21 +-- scripts/tweak-test-upgrade.sh | 182 ++++++++++++++++++++++++ scripts/upgrade/v6_to_7/post_08_wasm.sh | 18 +++ scripts/upgrade/v6_to_7/pre_08_wasm.sh | 18 +++ 13 files changed, 381 insertions(+), 90 deletions(-) create mode 100755 scripts/old-node/push-08-wasm.sh create mode 100755 scripts/old-node/testnode.sh create mode 100755 scripts/tweak-test-upgrade.sh create mode 100644 scripts/upgrade/v6_to_7/post_08_wasm.sh create mode 100644 scripts/upgrade/v6_to_7/pre_08_wasm.sh diff --git a/Makefile b/Makefile index 28c96ab31..9aaac731e 100644 --- a/Makefile +++ b/Makefile @@ -158,4 +158,16 @@ ictest-push-wasm: .PHONY: ictest-start-cosmos ictest-start-polkadot ictest-ibc ictest-push-wasm ictest-all -include contrib/make/release.mk \ No newline at end of file +include contrib/make/release.mk + + +test-upgrade: clean-testing-data + @echo "Starting upgrade test" + ./scripts/tweak-test-upgrade.sh + + +clean-testing-data: + @echo "Killing binary and removing previous data" + -@pkill centaurid 2>/dev/null + -@rm -rf ./mytestnet + diff --git a/app/ibctesting/endpoint.go b/app/ibctesting/endpoint.go index 95c9f3e95..99c2cb799 100644 --- a/app/ibctesting/endpoint.go +++ b/app/ibctesting/endpoint.go @@ -97,8 +97,7 @@ func (endpoint *Endpoint) CreateClient() (err error) { return err } consensusState = &wasmtypes.ConsensusState{ - Data: wasmConsensusState, - Timestamp: tmConsensusState.GetTimestamp(), + Data: wasmConsensusState, } default: err = fmt.Errorf("client type %s is not supported", endpoint.ClientConfig.GetClientType()) diff --git a/app/ibctesting/path.go b/app/ibctesting/path.go index 77dda9b59..3db241c57 100644 --- a/app/ibctesting/path.go +++ b/app/ibctesting/path.go @@ -31,7 +31,7 @@ func NewPath(chainA, chainB *TestChain) *Path { func NewDefaultEndpoint(chain *TestChain) *Endpoint { return &Endpoint{ Chain: chain, - ClientConfig: ibctesting.NewTendermintConfig(chain.UseWasmClient), + ClientConfig: ibctesting.NewTendermintConfig(), ConnectionConfig: ibctesting.NewConnectionConfig(), ChannelConfig: ibctesting.NewChannelConfig(), } diff --git a/app/ibctesting/simapp/export.go b/app/ibctesting/simapp/export.go index df6d8da75..50e47a7f5 100644 --- a/app/ibctesting/simapp/export.go +++ b/app/ibctesting/simapp/export.go @@ -4,7 +4,6 @@ import ( "encoding/json" "log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -18,7 +17,7 @@ func (app *SimApp) ExportAppStateAndValidators( forZeroHeight bool, jailAllowedAddrs []string, ) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block - ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + ctx := app.NewContext(true) // We export at last height + 1, because that's the height at which // Tendermint will start InitChain. @@ -75,12 +74,17 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] // withdraw all validator commission app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) + + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator().String()) return false }) // withdraw all delegator rewards - dels := app.StakingKeeper.GetAllDelegations(ctx) + dels, err := app.StakingKeeper.GetAllDelegations(ctx) + if err != nil { + panic(err) + } + for _, delegation := range dels { valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) if err != nil { diff --git a/app/ibctesting/wasm.go b/app/ibctesting/wasm.go index b6548ff4d..cb65d697f 100644 --- a/app/ibctesting/wasm.go +++ b/app/ibctesting/wasm.go @@ -1,7 +1,6 @@ package ibctesting import ( - "fmt" "time" "github.com/stretchr/testify/require" @@ -13,13 +12,13 @@ import ( // ConstructUpdateWasmClientHeader will construct a valid 08-wasm Header with a zero height // to update the light client on the source chain. -func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.Header, error) { +func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.ClientState, error) { return chain.ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight()) } // ConstructUpdateWasmClientHeaderWithTrustedHeight will construct a valid 08-wasm Header // to update the light client on the source chain. -func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*wasmtypes.Header, error) { +func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*wasmtypes.ClientState, error) { tmHeader, err := chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, trustedHeight) if err != nil { return nil, err @@ -30,26 +29,18 @@ func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight(counter return nil, err } - height, ok := tmHeader.GetHeight().(clienttypes.Height) - if !ok { - return nil, fmt.Errorf("error casting exported height to clienttypes height") - } - wasmHeader := wasmtypes.Header{ - Data: tmWasmHeaderData, - Height: height, + wasmHeader := wasmtypes.ClientState{ + Data: tmWasmHeaderData, } return &wasmHeader, nil } -func (chain *TestChain) CreateWasmClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, _, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *wasmtypes.Header { +func (chain *TestChain) CreateWasmClientHeader(chainID string, blockHeight int64, trustedHeight clienttypes.Height, timestamp time.Time, tmValSet, _, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *wasmtypes.ClientState { tmHeader := chain.CreateTMClientHeader(chainID, blockHeight, trustedHeight, timestamp, tmValSet, tmTrustedVals, signers) tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) require.NoError(chain.t, err) - height, ok := tmHeader.GetHeight().(clienttypes.Height) - require.True(chain.t, ok) - return &wasmtypes.Header{ - Data: tmWasmHeaderData, - Height: height, + return &wasmtypes.ClientState{ + Data: tmWasmHeaderData, } } diff --git a/go.mod b/go.mod index 724d26837..d378124ed 100644 --- a/go.mod +++ b/go.mod @@ -366,6 +366,7 @@ replace ( // github.com/cosmos/ibc-go/modules/light-clients/08-wasm => github.com/notional-labs/ibc-go/modules/light-clients/08-wasm v0.0.0-20240330020027-fa949b150972 + github.com/cosmos/ibc-go/modules/light-clients/08-wasm => /Users/kien6034/go/pkg/mod/github.com/cosmos/ibc-go/modules/light-clients/08-wasm@v0.1.1-0.20231213092650-57fcdb9a9a9d // use cosmos-compatible protobufs github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/scripts/localnode.sh b/scripts/localnode.sh index 1d39849e9..a6a0edeb9 100755 --- a/scripts/localnode.sh +++ b/scripts/localnode.sh @@ -1,11 +1,19 @@ #!/bin/bash - -echo "starting localnode" - BINARY=$1 +KEY="mykey" +CHAINID="localpica" +MONIKER="localtestnet" +KEYALGO="secp256k1" +KEYRING="test" +LOGLEVEL="info" CONTINUE=${CONTINUE:-"false"} +# to trace evm +#TRACE="--trace" +TRACE="" + HOME_DIR=mytestnet -ENV=${ENV:-""} +DENOM=${2:-ppica} + if [ "$CONTINUE" == "true" ]; then echo "\n ->> continuing from previous state" @@ -13,58 +21,29 @@ if [ "$CONTINUE" == "true" ]; then exit 0 fi + +# remove existing daemon rm -rf $HOME_DIR -pkill centaurid -# check DENOM is set. If not, set to upica -DENOM=${2:-ppica} -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 +# centaurid config keyring-backend $KEYRING +# centaurid config chain-id $CHAINID -# check BINARY is set. If not, build centaurid and set BINARY -if [ -z "$BINARY" ]; then - make build - BINARY=centaurid -fi +# if $KEY exists it should be deleted +$BINARY init $MONIKER --chain-id $CHAINID --home $HOME_DIR > /dev/null 2>&1 -CHAIN_ID="localpica" -KEYRING="test" -KEY="test0" -KEY1="test1" -KEY2="test2" +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" | $BINARY keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover --home $HOME_DIR -# 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 +$BINARY add-genesis-account $KEY 100000000000000000000000000$DENOM --keyring-backend $KEYRING --home $HOME_DIR -$BINARY add-genesis-account centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs "1000000000000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR + +# Sign genesis transaction +$BINARY gentx $KEY 1000000000000000000000$DENOM --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR update_test_genesis '.app_state["gov"]["params"]["voting_period"]="5s"' update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' @@ -72,23 +51,24 @@ update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DEN 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 = "1000ms"/' $HOME_DIR/config/config.toml +# sed -i 's/timeout_commit = "5s"/timeout_commit = "500ms"/' $HOME_DIR/config/config.toml +echo "updating.." +sed -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 + +if [[ $1 == "pending" ]]; then + echo "pending mode is on, please wait for the first block committed." +fi + +# update request max size so that we can upload the light client +# '' -e is a must have params on mac, if use linux please delete before run +sed -i'' -e 's/max_body_bytes = /max_body_bytes = 1/g' $HOME_DIR/config/config.toml +# Start the node (remove the --pruning=nothing flag if historical queries are not needed) +$BINARY start --pruning=nothing --minimum-gas-prices=0$DENOM --rpc.laddr tcp://0.0.0.0:26657 --home $HOME_DIR --log_level debug diff --git a/scripts/old-node/push-08-wasm.sh b/scripts/old-node/push-08-wasm.sh new file mode 100755 index 000000000..a8184b6db --- /dev/null +++ b/scripts/old-node/push-08-wasm.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +KEY="mykey" +KEYALGO="secp256k1" +KEYRING="test" +HOME_DIR="mytestnet" +# validate dependencies are installed +command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; } + +./_build/old/centaurid tx 08-wasm push-wasm contracts/ics10_grandpa_cw.wasm --from=mykey --gas 10002152622 --fees 10020166upica --keyring-backend test --chain-id=localpica -y --home $HOME_DIR + +sleep 5 + +./_build/old/centaurid query 08-wasm all-wasm-code --home $HOME_DIR \ No newline at end of file diff --git a/scripts/old-node/testnode.sh b/scripts/old-node/testnode.sh new file mode 100755 index 000000000..2911edc98 --- /dev/null +++ b/scripts/old-node/testnode.sh @@ -0,0 +1,71 @@ +#!/bin/bash +BINARY=${1:-_build/old/centaurid} +KEY="mykey" +CHAINID="localpica" +MONIKER="localtestnet" +KEYALGO="secp256k1" +KEYRING="test" +LOGLEVEL="info" +CONTINUE=${CONTINUE:-"false"} +# to trace evm +#TRACE="--trace" +TRACE="" + +HOME_DIR=~/.banksy +DENOM=upica + +if [ "$CONTINUE" == "true" ]; then + echo "\n ->> continuing from previous state" + $BINARY start --home $HOME_DIR --log_level debug + exit 0 +fi + + +# remove existing daemon +rm -rf $HOME_DIR + +# centaurid config keyring-backend $KEYRING +# centaurid config chain-id $CHAINID + +# if $KEY exists it should be deleted +$BINARY init $MONIKER --chain-id $CHAINID --home $HOME_DIR > /dev/null 2>&1 + +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" | $BINARY keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover --home $HOME_DIR + +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 +} + +# Allocate genesis accounts (cosmos formatted addresses) +$BINARY add-genesis-account $KEY 100000000000000000000000000$DENOM --keyring-backend $KEYRING --home $HOME_DIR + + +# Sign genesis transaction +$BINARY gentx $KEY 1000000000000000000000$DENOM --keyring-backend $KEYRING --chain-id $CHAINID --home $HOME_DIR + +update_test_genesis '.app_state["gov"]["params"]["voting_period"]="50s"' +update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' +update_test_genesis '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "0"}]' +update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}' +update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' + +# sed -i 's/timeout_commit = "5s"/timeout_commit = "500ms"/' $HOME_DIR/config/config.toml + + +# 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 + +if [[ $1 == "pending" ]]; then + echo "pending mode is on, please wait for the first block committed." +fi + +# update request max size so that we can upload the light client +# '' -e is a must have params on mac, if use linux please delete before run +sed -i'' -e 's/max_body_bytes = /max_body_bytes = 1/g' $HOME_DIR/config/config.toml + +# Start the node (remove the --pruning=nothing flag if historical queries are not needed) +$BINARY start --pruning=nothing --minimum-gas-prices=0.0001$DENOM --rpc.laddr tcp://0.0.0.0:26657 --home $HOME_DIR --log_level debug diff --git a/scripts/testnode.sh b/scripts/testnode.sh index 009f8889c..41eb8b0ee 100755 --- a/scripts/testnode.sh +++ b/scripts/testnode.sh @@ -1,5 +1,6 @@ #!/bin/bash +BINARY=$1 KEY="mykey" CHAINID="localpica" MONIKER="localtestnet" @@ -17,13 +18,13 @@ DENOM=${2:-ppica} # remove existing daemon rm -rf ~/.banksy* -# centaurid config keyring-backend $KEYRING -# centaurid config chain-id $CHAINID +# $BINARY config keyring-backend $KEYRING +# $BINARY config chain-id $CHAINID # if $KEY exists it should be deleted -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" | centaurid keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover +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" | $BINARY keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover -centaurid init $MONIKER --chain-id $CHAINID > /dev/null 2>&1 +$BINARY init $MONIKER --chain-id $CHAINID > /dev/null 2>&1 update_test_genesis () { # update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"' @@ -31,12 +32,12 @@ update_test_genesis () { } # Allocate genesis accounts (cosmos formatted addresses) -centaurid genesis add-genesis-account $KEY 100000000000000000000000000ppica --keyring-backend $KEYRING -centaurid add-genesis-account centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs "1000000000000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR +$BINARY genesis add-genesis-account $KEY 100000000000000000000000000ppica --keyring-backend $KEYRING +$BINARY add-genesis-account centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs "1000000000000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR # Sign genesis transaction -centaurid genesis gentx $KEY 1000000000000000000000ppica --keyring-backend $KEYRING --chain-id $CHAINID +$BINARY gentx $KEY 1000000000000000000000ppica --keyring-backend $KEYRING --chain-id $CHAINID update_test_genesis '.app_state["gov"]["params"]["voting_period"]="20s"' update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' @@ -45,10 +46,10 @@ update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","a update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' # Collect genesis tx -centaurid collect-gentxs +$BINARY collect-gentxs # Run this to ensure everything worked and that the genesis file is setup correctly -centaurid validate-genesis +$BINARY validate-genesis if [[ $1 == "pending" ]]; then echo "pending mode is on, please wait for the first block committed." @@ -59,4 +60,4 @@ fi sed -i'' -e 's/max_body_bytes = /max_body_bytes = 1/g' ~/.banksy/config/config.toml # Start the node (remove the --pruning=nothing flag if historical queries are not needed) -centaurid start --pruning=nothing --minimum-gas-prices=0.0001ppica --rpc.laddr tcp://0.0.0.0:26657 +$BINARY start --pruning=nothing --minimum-gas-prices=0.0001ppica --rpc.laddr tcp://0.0.0.0:26657 diff --git a/scripts/tweak-test-upgrade.sh b/scripts/tweak-test-upgrade.sh new file mode 100755 index 000000000..d9476c2f3 --- /dev/null +++ b/scripts/tweak-test-upgrade.sh @@ -0,0 +1,182 @@ +#!/bin/bash + +# the upgrade is a fork, "true" otherwise +FORK=${FORK:-"false"} + +OLD_VERSION=kien-v6.5.0-tweak +UPGRADE_WAIT=${UPGRADE_WAIT:-20} +HOME=mytestnet +ROOT=$(pwd) +DENOM=upica +CHAIN_ID=localpica +SOFTWARE_UPGRADE_NAME="v7_0_1" +ADDITIONAL_PRE_SCRIPTS="./scripts/upgrade/v6_to_7/pre_08_wasm.sh" +ADDITIONAL_AFTER_SCRIPTS="./scripts/upgrade/v6_to_7/post_08_wasm.sh" + +SLEEP_TIME=1 + +KEY="mykey" +KEY1="test1" +KEY2="test2" + +if [[ "$FORK" == "true" ]]; then + export PICA_HALT_HEIGHT=20 +fi + +# underscore so that go tool will not take gocache into account +mkdir -p _build/gocache +export GOMODCACHE=$ROOT/_build/gocache + + + +# install old binary if not exist +if [ ! -f "_build/$OLD_VERSION.zip" ] &> /dev/null +then + mkdir -p _build/old + wget -c "https://github.com/notional-labs/composable-cosmos/archive/refs/tags/${OLD_VERSION}.zip" -O _build/${OLD_VERSION}.zip + unzip _build/${OLD_VERSION}.zip -d _build +fi + + +# reinstall old binary +if [ $# -eq 1 ] && [ $1 == "--reinstall-old" ] || ! command -v _build/old/centaurid &> /dev/null; then + cd ./_build/composable-cosmos-${OLD_VERSION} + GOBIN="$ROOT/_build/old" go install -mod=readonly ./... + cd ../.. +fi + + +# install new binary +FORCE_BUILD=${FORCE_BUILD:-"false"} +if ! command -v _build/new/centaurid &> /dev/null || [[ "$FORCE_BUILD" == "true" ]]; then + echo "Building the new binary..." + mkdir -p _build/new + GOBIN="$ROOT/_build/new" go install -mod=readonly ./... +fi + +# run old node +# if [[ "$OSTYPE" == "darwin"* ]]; then + +# else +# screen node1 bash scripts/localnode.sh _build/old/centaurid $DENOM +# fi +echo "running old node" +screen -dms old-node bash scripts/localnode.sh _build/old/centaurid $DENOM + +sleep 2 # wait for note to start + +# execute additional pre scripts +if [ ! -z "$ADDITIONAL_PRE_SCRIPTS" ]; then + # slice ADDITIONAL_SCRIPTS by , + SCRIPTS=($(echo "$ADDITIONAL_PRE_SCRIPTS" | tr ',' ' ')) + for SCRIPT in "${SCRIPTS[@]}"; do + # check if SCRIPT is a file + if [ -f "$SCRIPT" ]; then + echo "executing additional pre scripts from $SCRIPT" + source $SCRIPT + sleep 2 + else + echo "$SCRIPT is not a file" + fi + done +fi + + +run_fork () { + echo "forking" + + while true; do + BLOCK_HEIGHT=$(./_build/old/centaurid status | jq '.SyncInfo.latest_block_height' -r) + # if BLOCK_HEIGHT is not empty + if [ ! -z "$BLOCK_HEIGHT" ]; then + echo "BLOCK_HEIGHT = $BLOCK_HEIGHT" + sleep 10 + else + echo "BLOCK_HEIGHT is empty, forking" + break + fi + done +} + +run_upgrade () { + echo -e "\n\n=> =>start upgrading" + + # Get upgrade height, 12 block after (6s) + STATUS_INFO=($(./_build/old/centaurid status --home $HOME | jq -r '.NodeInfo.network,.SyncInfo.latest_block_height')) + UPGRADE_HEIGHT=$((STATUS_INFO[1] + 18)) + echo "UPGRADE_HEIGHT = $UPGRADE_HEIGHT" + + 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/centaurid.tar?checksum=sha256:'"$SUM"'", + } + }') + + + ./_build/old/centaurid tx gov submit-legacy-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "$UPGRADE_INFO" --title "upgrade" --description "upgrade" --from $KEY --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y > /dev/null + + sleep $SLEEP_TIME + + ./_build/old/centaurid tx gov deposit 1 "20000000${DENOM}" --from $KEY --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y > /dev/null + + sleep $SLEEP_TIME + + ./_build/old/centaurid tx gov vote 1 yes --from $KEY --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y > /dev/null + + sleep $SLEEP_TIME + + # ./_build/old/centaurid tx gov vote 1 yes --from $KEY2 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y > /dev/null + + # sleep $SLEEP_TIME + + # determine block_height to halt + while true; do + BLOCK_HEIGHT=$(./_build/old/centaurid status | jq '.SyncInfo.latest_block_height' -r) + if [ $BLOCK_HEIGHT = "$UPGRADE_HEIGHT" ]; then + # assuming running only 1 centaurid + echo "BLOCK HEIGHT = $UPGRADE_HEIGHT REACHED, KILLING OLD ONE" + pkill centaurid + break + else + ./_build/old/centaurid q gov proposal 1 --output=json | jq ".status" + echo "BLOCK_HEIGHT = $BLOCK_HEIGHT" + sleep 1 + fi + done +} + +# if FORK = true +if [[ "$FORK" == "true" ]]; then + run_fork + unset PICA_HALT_HEIGHT +else + run_upgrade +fi + +sleep 1 + +# run new node +echo -e "\n\n=> =>continue running nodes after upgrade" +CONTINUE="true" screen -dms new-node bash scripts/localnode.sh _build/new/centaurid $DENOM + +sleep 5 + + +# execute additional after scripts +if [ ! -z "$ADDITIONAL_AFTER_SCRIPTS" ]; then + # slice ADDITIONAL_SCRIPTS by , + SCRIPTS=($(echo "$ADDITIONAL_AFTER_SCRIPTS" | tr ',' ' ')) + for SCRIPT in "${SCRIPTS[@]}"; do + # check if SCRIPT is a file + if [ -f "$SCRIPT" ]; then + echo "executing additional after scripts from $SCRIPT" + source $SCRIPT _build/new/centaurid + sleep 5 + else + echo "$SCRIPT is not a file" + fi + done +fi \ No newline at end of file diff --git a/scripts/upgrade/v6_to_7/post_08_wasm.sh b/scripts/upgrade/v6_to_7/post_08_wasm.sh new file mode 100644 index 000000000..a813cf858 --- /dev/null +++ b/scripts/upgrade/v6_to_7/post_08_wasm.sh @@ -0,0 +1,18 @@ +#!/bin/bash +KEY="mykey" +KEYALGO="secp256k1" +KEYRING="test" +HOME_DIR="mytestnet" + + +sleep 2 + +checksum=$(./_build/new/centaurid query ibc-wasm checksums --home $HOME_DIR -o json | jq -r '.checksums[0]') + +if ./_build/new/centaurid query ibc-wasm code $checksum --home $HOME_DIR -o json &> /dev/null; then + echo "Code with checksum $checksum exists." +else + echo "Code with checksum $checksum does not exist." +fi + + diff --git a/scripts/upgrade/v6_to_7/pre_08_wasm.sh b/scripts/upgrade/v6_to_7/pre_08_wasm.sh new file mode 100644 index 000000000..4058c1ff3 --- /dev/null +++ b/scripts/upgrade/v6_to_7/pre_08_wasm.sh @@ -0,0 +1,18 @@ +#!/bin/bash +KEY="mykey" +KEYALGO="secp256k1" +KEYRING="test" +HOME_DIR="mytestnet" + + + +# validate dependencies are installed +command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; } + + +stat $(pwd)/contracts/ics10_grandpa_cw.wasm +./_build/old/centaurid tx 08-wasm push-wasm $(pwd)/contracts/ics10_grandpa_cw.wasm --from=mykey --gas 10002152622 --fees 10020166upica --keyring-backend test --chain-id=localpica -y --home $HOME_DIR + +sleep 3 + +./_build/old/centaurid query 08-wasm all-wasm-code --home $HOME_DIR \ No newline at end of file