Skip to content

Commit

Permalink
Kien/setup test upgrade 08 wasms (#19)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kienn6034 authored Apr 2, 2024
1 parent 69bc4b5 commit afbc54b
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 90 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

3 changes: 1 addition & 2 deletions app/ibctesting/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion app/ibctesting/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
12 changes: 8 additions & 4 deletions app/ibctesting/simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 7 additions & 16 deletions app/ibctesting/wasm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ibctesting

import (
"fmt"
"time"

"github.com/stretchr/testify/require"
Expand All @@ -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
Expand All @@ -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,
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
92 changes: 36 additions & 56 deletions scripts/localnode.sh
Original file line number Diff line number Diff line change
@@ -1,94 +1,74 @@
#!/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"
$BINARY start --home $HOME_DIR --log_level debug
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'"'
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 = "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
14 changes: 14 additions & 0 deletions scripts/old-node/push-08-wasm.sh
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions scripts/old-node/testnode.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit afbc54b

Please sign in to comment.