Skip to content

Commit

Permalink
add scripts (#492)
Browse files Browse the repository at this point in the history
* delete proposal #6

* use develop branch for ci

* use another image

* test

* removing more broken proposals

* introduce goreleaser

* remove separate gha for building docker images

* rename registry owner

* clean comments

* use version with v

* add additional tags

* fix org

* update docker image

* added jq

* introduce ibc transfer custom module

* custom ibc transfer module ready to replace for testing.

* activate custom ibc module for cosmos chain. chain works.

* added ibc transfer module that is going to store all params for eth fees

* resolve conflict with a same name for MsgUpdateEpochParams from staking.

* add dependency to transfer keeper from ibc transfer middleware/params

* added repeated FeeItem into Params + MVP logic in transfer msg server

* finalized the Transfer method. send fee to fee. build. chain works.

* only useful params in genesis for ibc transfer module. Works

* golangci-lint run

* slashing fixes

* remove unused types in proto

* add docs and fix all requested changes by reviewers

* review fixes

* fix tests

* local setup

* allow devnet with custom key gov

* relay from master

* porting fix from v7

* refactoring.

* add runtime upgrade handler. for ibc fee feature.

* upgrade merged. BankKeeper + GovKeeper + IbcTransferMiddlewareKeeper

* Revert "Merge pull request #451 from ComposableFi/slashing_fix"

This reverts commit 1ad4293, reversing
changes made to 85e2bf9.

* revert banksy changes to resolve halted chain.

* Revert "allow devnet with custom key gov"

This reverts commit 2457d87.

* create a new chain upgrade handler for chain upgrade.

* chore: change centaurid -> picad and prefix name to pica

* chore: update name prefix

* refactor: remove old upgrade

* refactor: update prefix

* refactor: update prefix

* test: change govAuthorityAddress

* ci: rollback

* wip

* feat: add script upgrade_test

* chore: update script

* wip

* refactor: remove set prefix

* refactor: update test

* chore: rollback

* chore: ignore build folder

* perf: make blocktime run faster

* fix: use key with balances

* chore: ignore screen log

* refactor: using default flag for test

* test: increment and assert counter value to be equal 1

* chore: rollback

* chore: rollback script

* test: add script upgrade

* fix: correct upgrade height

* feat: add post scripts

* test: assertion for post scripts

* chore: stream unnecessary output to null

* feat: add test for the new address

* wip

* chore: log for test upgrade

* test: completed ibc transfer

* verify affection of alliance module

* test/ica_migration

* add migration test for mint, ratelimit, ibc-hooks, transfermiddleware module

* finalize script upgrade test

* pick denom for testing as stake

* remove unused fnc

* modify testup

* fix unused fnc

* merge variable

* chore: remove release.yml

* refactor: change v6.4.6 -> v6.4.7

* feaT: migrate contract info

* test: assert contract info && code info

* fix: change repo secret name

* refactor: change v6.4.7 -> v6.4.8

* revert change version

* rebase and change conflict version

* merge from develop2

* feat: add v6_6_0 handler

* remove old upgrade

* fix lint

* fix lint

* fix test

* update script

* update address and ibc-go

* fix lint

* fix lint

* feat: init deps

* Kien/e2e test migrate (#23)

* 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

* fix: migration transfermiddleware

* allow pica12smx2wdlyttvyzvzg54y2vnqwq2qjate0ww798 in local

* fix lint

---------

Co-authored-by: kkast <kkastsevich@gmail.com>
Co-authored-by: Kanstantsin Kastsevich <kkast@users.noreply.github.com>
Co-authored-by: rjonczy <robert.jonczy@gmail.com>
Co-authored-by: rustdev <placex.com@gmail.com>
Co-authored-by: rust.dev <102041955+RustNinja@users.noreply.github.com>
Co-authored-by: dzmitry-lahoda <dzmitry@lahoda.pro>
Co-authored-by: tungle <anhletung@notional.ventures>
Co-authored-by: kienn6034 <kien@notional.ventures>
  • Loading branch information
9 people committed Apr 15, 2024
1 parent 04548a3 commit 362a1cc
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 64 deletions.
8 changes: 7 additions & 1 deletion bech32-migration/transfermiddleware/transfermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ func MigrateAddressBech32(ctx sdk.Context, storeKey storetypes.StoreKey, cdc cod
allowRelayAddressCount := uint64(0)

store := ctx.KVStore(storeKey)

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

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)
}
if allowRelayAddressCount == 0 {
// TODO: only using in localtest
store.Set(types.GetKeyByRlyAddress("pica12smx2wdlyttvyzvzg54y2vnqwq2qjate0ww798"), relayAddressPrefix)
}

ctx.Logger().Info(
Expand Down
1 change: 1 addition & 0 deletions scripts/08-wasm/ics10_grandpa_cw.wasm.json

Large diffs are not rendered by default.

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
47 changes: 47 additions & 0 deletions scripts/upgrade/init_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash


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

COMPOSABLE_VERSION="branchfortestingpfmfix"

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/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
if ! command -v _build/new/picad &> /dev/null
then
mkdir -p _build/new
GOBIN="$ROOT/_build/new" go install -mod=readonly ./...
fi

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

23 changes: 23 additions & 0 deletions scripts/upgrade/v_6_4_8/setup-08-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
KEY=mykey
KEYALGO="secp256k1"
KEYRING="test"
HOME_DIR="mytestnet"
BINARY=_build/old/centaurid
DENOM=ppica
CHAINID=centauri-dev

$BINARY tx gov submit-proposal scripts/08-wasm/ics10_grandpa_cw.wasm.json --from=$KEY --fees 100000${DENOM} --gas auto --keyring-backend test --home $HOME_DIR --chain-id $CHAINID -y

sleep 2
# TODO: fetch the propsoal id dynamically
$BINARY tx gov deposit "1" "20000000ppica" --from $KEY --fees 100000${DENOM} --keyring-backend test --home $HOME_DIR --chain-id $CHAINID -y

sleep 2
$BINARY tx gov vote 1 yes --from $KEY --fees 100000${DENOM} --keyring-backend test --home $HOME_DIR --chain-id $CHAINID -y


## Voting time is 5s, check in localnode.sh
sleep 5

$BINARY query 08-wasm all-wasm-code --home $HOME_DIR --chain-id $CHAINID

0 comments on commit 362a1cc

Please sign in to comment.