Skip to content

Commit

Permalink
Kien/e2e test migrate (#23)
Browse files Browse the repository at this point in the history
* feat: run locanode and push wasm code

* feat: setup relayer

* feat: using ngit for repo with nix

* chore: update notes install deps

* feat: script to upgrade

* fix: upgrade scripts

* fix: init deps script

* fix/migration: wrong prefix relay addresS
  • Loading branch information
kienn6034 authored Apr 15, 2024
1 parent 894d41e commit 2da489b
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 121 deletions.
6 changes: 4 additions & 2 deletions bech32-migration/transfermiddleware/transfermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ func MigrateAddressBech32(ctx sdk.Context, storeKey storetypes.StoreKey, cdc cod
allowRelayAddressCount := uint64(0)

store := ctx.KVStore(storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyRlyAddress)

relayAddressPrefix := []byte{1}
iterator := sdk.KVStorePrefixIterator(store, relayAddressPrefix)

for ; iterator.Valid(); iterator.Next() {
allowRelayAddressCount++
trimedAddr := strings.Replace(string(iterator.Key()), "\x04", "", 1)
newPrefixAddr := utils.ConvertAccAddr(trimedAddr)
store.Set(types.GetKeyByRlyAddress(newPrefixAddr), []byte{1})
store.Set(types.GetKeyByRlyAddress(newPrefixAddr), relayAddressPrefix)
}

ctx.Logger().Info(
Expand Down
103 changes: 40 additions & 63 deletions scripts/localnode.sh
Original file line number Diff line number Diff line change
@@ -1,93 +1,70 @@
#!/bin/bash

echo "starting localnode"

KEY="mykey"
KEY1="mykey1"
CHAINID="centauri-dev"
MONIKER="localtestnet"
KEYALGO="secp256k1"
KEYRING="test"
LOGLEVEL="info"
BINARY=$1
CONTINUE=${CONTINUE:-"false"}
# to trace evm
#TRACE="--trace"
TRACE=""

HOME_DIR=mytestnet
ENV=${ENV:-""}
DENOM=ppica


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
$BINARY config keyring-backend $KEYRING
$BINARY config chain-id $CHAINID

# check BINARY is set. If not, build picad and set BINARY
if [ -z "$BINARY" ]; then
make build
BINARY=build/picad
fi
# remove existing daemon
rm -rf $HOME_DIR

CHAIN_ID="localpica"
KEYRING="test"
KEY="test0"
KEY1="test1"
KEY2="test2"
# 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" | $BINARY keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover --home $HOME_DIR
echo "bottom loan skill merry east cradle onion journey palm apology verb edit desert impose absurd oil bubble sweet glove shallow size build burst effort" | $BINARY keys add $KEY1 --keyring-backend $KEYRING --algo $KEYALGO --recover --home $HOME_DIR
$BINARY init $CHAINID --chain-id $CHAINID --default-denom "ppica" --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
cat $HOME_DIR/config/genesis.json | jq "$1" > $HOME_DIR/config/tmp_genesis.json && cp $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 100000000000000000000000000ppica --keyring-backend $KEYRING --home $HOME_DIR
$BINARY add-genesis-account $KEY1 100000000000000000000000000ppica --keyring-backend $KEYRING --home $HOME_DIR

# Sign genesis transaction
$BINARY gentx $KEY 10030009994127689ppica --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["gov"]["params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1"}]'
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

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
sed -i'' -e 's/max_tx_bytes = 1048576/max_tx_bytes = 10000000/g' $HOME_DIR/config/config.toml
sed -i'' -e 's/timeout_commit = "5s"/timeout_commit = "1s"/' $HOME_DIR/config/config.toml


$BINARY start --rpc.unsafe --rpc.laddr tcp://0.0.0.0:26657 --pruning=nothing --minimum-gas-prices=0.001ppica --home=$HOME_DIR --log_level trace --trace --with-tendermint=true --transport=socket --grpc.enable=true --grpc-web.enable=false --api.enable=true --p2p.pex=false --p2p.upnp=false
39 changes: 0 additions & 39 deletions scripts/upgrade/init-old-node-env.sh

This file was deleted.

26 changes: 16 additions & 10 deletions scripts/upgrade/init_deps.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
#!/bin/bash


OLD_VERSION=v6.5.2
OLD_VERSION=kien-devnet-651
SOFTWARE_UPGRADE_NAME="v6_6_0"
ROOT=$(pwd)

COMPOSABLE_VERSION="pfm-fix"
COMPOSABLE_VERSION="branchfortestingpfmfix"

if [ ! -f "_build/composable/$COMPOSABLE_VERSION.zip" ] &> /dev/null
then
mkdir -p _build/composable
wget -c "https://github.com/notional-labs/composable/archive/refs/tags/${COMPOSABLE_VERSION}.zip" -O _build/composable/${COMPOSABLE_VERSION}.zip
unzip _build/composable/${COMPOSABLE_VERSION}.zip -d _build/composable
fi
mkdir -p _build/


# Check if the directory exists and is a Git repository
# TODO: using git, since nix in composable repo requires something with git
# Consider using submodule, or firgure this out
if [ ! -d "_build/composable/.git" ]; then
cd _build/
git clone https://github.com/ComposableFi/composable.git composable
cd composable
git checkout "$COMPOSABLE_VERSION"
cd ../.././
fi


# install old binary if not exist
if [ ! -f "_build/$OLD_VERSION.zip" ] &> /dev/null
then
mkdir -p _build/old
wget -c "https://github.com/ComposableFi/composable-cosmos/archive/refs/tags/${OLD_VERSION}.zip" -O _build/${OLD_VERSION}.zip
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:1}
cd ./_build/composable-cosmos-${OLD_VERSION}
GOBIN="$ROOT/_build/old" go install -mod=readonly ./...
cd ../..
fi
Expand Down
13 changes: 13 additions & 0 deletions scripts/upgrade/old-node-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ADDITIONAL_SCRIPTS=(
"./scripts/upgrade/v_6_4_8/setup-08-wasm.sh"
)

for SCRIPT in "${ADDITIONAL_SCRIPTS[@]}"; do
if [ -f "$SCRIPT" ]; then
echo "Running additional script: $SCRIPT"
source $SCRIPT
else
echo "Additional script $SCRIPT does not exist."
fi
done

25 changes: 25 additions & 0 deletions scripts/upgrade/setup-old-centaurid-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# the upgrade is a fork, "true" otherwise
FORK=${FORK:-"false"}


BINARY=_build/old/centaurid
HOME=mytestnet
ROOT=$(pwd)
DENOM=ppica
CHAIN_ID=centaurid

ADDITIONAL_PRE_SCRIPTS="./scripts/upgrade/old-node-scripts.sh"

SLEEP_TIME=1


screen -L -dmS node1 bash scripts/localnode.sh $BINARY $DENOM --Logfile $HOME/log-screen.txt
#scripts/localnode.sh $BINARY

sleep 4 # wait for note to start

# execute additional pre scripts
source $ADDITIONAL_PRE_SCRIPTS

6 changes: 6 additions & 0 deletions scripts/upgrade/setup-polkadot-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ROOT=$(pwd)

cd $ROOT/_build/composable

# This start the node
nix run .#zombienet-rococo-local-picasso-dev
20 changes: 20 additions & 0 deletions scripts/upgrade/setup-relayer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

ROOT=$(pwd)

cd $ROOT/_build/composable/

# init clients
nix run .#picasso-centauri-ibc-init
sleep 1

# init connection
nix run .#picasso-centauri-ibc-connection-init
sleep 1

# init channel
nix run .#picasso-centauri-ibc-channels-init
sleep 1

# run relayer
nix run .#picasso-centauri-ibc-relay
sleep 1
80 changes: 80 additions & 0 deletions scripts/upgrade/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# the upgrade is a fork, "true" otherwise
FORK=${FORK:-"false"}

UPGRADE_WAIT=${UPGRADE_WAIT:-20}
HOME=mytestnet
ROOT=$(pwd)
DENOM=ppica
CHAIN_ID=centauri-dev
SOFTWARE_UPGRADE_NAME="v6_6_0"
ADDITIONAL_PRE_SCRIPTS="./scripts/upgrade/v_6_4_8/pre-script.sh"
ADDITIONAL_AFTER_SCRIPTS="./scripts/upgrade/v_6_4_8/post-script.sh"
KEY="mykey"
KEY1="mykey1"

SLEEP_TIME=1


UPGRADE_PROPOSAL_ID=2
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] + 12))
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)
UPGRADE_INFO=$(jq -n '
{
"binaries": {
"linux/amd64": "file://'$(pwd)'/_build/new/picad.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 --fees 100000${DENOM} --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y > /dev/null

sleep $SLEEP_TIME

./_build/old/centaurid tx gov deposit $UPGRADE_PROPOSAL_ID "20000000${DENOM}" --from $KEY --keyring-backend test --fees 100000${DENOM} --chain-id $CHAIN_ID --home $HOME -y

sleep $SLEEP_TIME

./_build/old/centaurid tx gov vote $UPGRADE_PROPOSAL_ID yes --from $KEY --keyring-backend test --fees 100000${DENOM} --chain-id $CHAIN_ID --home $HOME -y

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 $UPGRADE_PROPOSAL_ID --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 -L -dmS picad bash scripts/localnode.sh _build/new/picad $DENOM
CONTINUE="true" bash scripts/localnode.sh _build/new/picad $DENOM

Loading

0 comments on commit 2da489b

Please sign in to comment.