Skip to content

Instantly share code, notes, and snippets.

@sainoe
Last active May 11, 2023 12:09
Show Gist options
  • Save sainoe/9d4b6995b900ffdc052dfdb3d4df5ff3 to your computer and use it in GitHub Desktop.
Save sainoe/9d4b6995b900ffdc052dfdb3d4df5ff3 to your computer and use it in GitHub Desktop.
Local tests for Gaia v10 migrations (https://github.com/cosmos/gaia/issues/2456)
#!/bin/bash
set -e
export GAIA_HOME=$HOME/.gaia
export UPGRADE_NAME_LOWERCASE=v10
export UPGRADE_HEIGHT=12
export OLDBINARY_HOME=$GAIA_HOME/cosmovisor/genesis/bin
export NEWBINARY_HOME=$GAIA_HOME/cosmovisor/upgrades/${UPGRADE_NAME_LOWERCASE}/bin
export OLDBINARY=$OLDBINARY_HOME/gaiad
export NEWBINARY=$NEWBINARY_HOME/gaiad
export NODEADDR=http://localhost
# save old binary global fee params
OLD_MIN_GAS_PRICES=$($OLDBINARY q globalfee min -o=json)
$OLDBINARY tx gov submit-proposal software-upgrade $UPGRADE_NAME_LOWERCASE \
--upgrade-height $UPGRADE_HEIGHT \
--title v10 \
--description "upgrade" \
--deposit 100000000stake \
--gas-prices 0.025stake \
--from val \
--home $GAIA_HOME \
-y
sleep 5
$OLDBINARY tx gov vote 1 yes \
--gas-prices 0.025stake \
--from val \
--home $GAIA_HOME \
-y
# wait the upgrade to be executed
while [ true ]; do
curr_block=$(curl -s $NODEADDR:26657/status | jq -r '.result.sync_info.latest_block_height')
echo current block $curr_block waiting for upgrade at block $UPGRADE_HEIGHT
if [[ ${curr_block} -gt $UPGRADE_HEIGHT ]]; then
sleep 5
break
fi
sleep 5
done
#TODO: check version when v10 is release is available
# curr_version=$(curl -s $NODEADDR:1317/cosmos/base/tendermint/v1beta1/node_info | jq -r '.application_version.version')
# define the expected params after v10 migration
default_globalfee_params='
{
"minimum_gas_prices": [],
"bypass_min_fee_msg_types": [
"/ibc.core.channel.v1.MsgRecvPacket",
"/ibc.core.channel.v1.MsgAcknowledgement",
"/ibc.core.client.v1.MsgUpdateClient",
"/ibc.core.channel.v1.MsgTimeout",
"/ibc.core.channel.v1.MsgTimeoutOnClose"
],
"max_total_bypass_min_fee_msg_gas_usage": "1000000"
}'
# update the default params with the old binary min gas price value
exp_global_fee_params=$(echo $default_globalfee_params | jq --argjson variable $OLD_MIN_GAS_PRICES '.minimum_gas_prices = $variable.minimum_gas_prices')
echo $exp_global_fee_params | jq .
# get current global fee params
curr_params=$($NEWBINARY q globalfee params -o=json)
# check we get the expected params
DIFF=$(diff <(echo ${exp_global_fee_params} | jq -r --sort-keys .) <(echo ${curr_params} | jq -r --sort-keys .))
if [ "$DIFF" != "" ]
then
printf "expected default global fee params:\n${DIFF}"
exit 1
fi
## test bypass msg types
# create and submit proposal to bypass fee for withdraw reward msgs
bypass_msg_prop='{
"title": "ChangeProposalBypassMsgss",
"description": "global fee change",
"changes": [
{
"subspace": "globalfee",
"key": "BypassMinFeeMsgTypes",
"value": [
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"
]
}
],
"deposit": "100000000stake"
}'
echo $bypass_msg_prop | jq . > prop.json
$NEWBINARY tx gov submit-proposal param-change prop.json \
--from val \
--gas-prices \
0.025stake \
-y
sleep 1
$NEWBINARY tx gov vote 2 yes \
--from val \
--gas-prices 0.025stake \
-y
sleep 20
$NEWBINARY tx distribution withdraw-all-rewards \
--from val \
-y \
#!/bin/bash
set -e
echo "**** testing Gaia v10 parameters migration ****"
GAIA_HOME=$HOME/.gaia
rm -rf $GAIA_HOME
export OLDBINARY_VERSION=v9.0.0
export NEWBINARY_VERSION=v10.0.0
export UPGRADE_NAME_LOWERCASE=v10
# install both v9 and v10 binaries
export OLDBINARY_URL="https://github.com/cosmos/gaia/releases/download/${OLDBINARY_VERSION}/gaiad-${OLDBINARY_VERSION}-darwin-arm64"
export NEWBINARY_URL="https://github.com/cosmos/gaia/releases/download/${NEWBINARY_VERSION}/gaiad-${NEWBINARY_VERSION}-darwin-amd64"
export OLDBINARY_HOME=$GAIA_HOME/cosmovisor/genesis/bin
export NEWBINARY_HOME=$GAIA_HOME/cosmovisor/upgrades/${UPGRADE_NAME_LOWERCASE}/bin
export OLDBINARY=$OLDBINARY_HOME/gaiad
export NEWBINARY=$NEWBINARY_HOME/gaiad
mkdir -p $OLDBINARY_HOME
curl -LJ -o $OLDBINARY $OLDBINARY_URL
chmod +x $OLDBINARY
mkdir -p $NEWBINARY_HOME
### TO BE CHANGED WHEN BINARY ARE AVAILABLE FOR v10 RELEASE
git clone https://github.com/cosmos/gaia.git
cd gaia
git checkout sainoe/global-fee-migration
make build
cp ./build/gaiad $NEWBINARY_HOME
cd $GAIA_HOME
###
# curl -LJ -o $NEWBINARY $NEWBINARY_URL
# chmod +x $NEWBINARY
echo "install the latest cosmovisor"
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest
export DAEMON_NAME=gaiad
# export DAEMON_HOME=$(pwd -P)/$GAIA_HOME
export DAEMON_HOME=$GAIA_HOME
export DAEMON_RESTART_AFTER_UPGRADE=true
export BROADCAST_MODE=block
echo "setup gaia home"
$OLDBINARY init mynode0 --chain-id test --home $GAIA_HOME
$OLDBINARY config chain-id test --home $GAIA_HOME
$OLDBINARY config keyring-backend test --home $GAIA_HOME
$OLDBINARY config broadcast-mode $BROADCAST_MODE --home $GAIA_HOME
$OLDBINARY config node tcp://localhost:26657 --home $GAIA_HOME
# Generate Genesis Accounts
$OLDBINARY keys add val --home $GAIA_HOME
$OLDBINARY add-genesis-account $($OLDBINARY keys show val -a --home $GAIA_HOME) 10000000000000000000stake --home $GAIA_HOME
$OLDBINARY gentx val 10000000000stake --chain-id test --home $GAIA_HOME
$OLDBINARY collect-gentxs --home $GAIA_HOME
#Configure App
sed -i '' 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025stake"/g' $GAIA_HOME/config/app.toml
# Configure Gov Params
# min deposition amount
sed -i '' 's%"amount": "10000000",%"amount": "1",%g' $GAIA_HOME/config/genesis.json
# min voting power that a proposal requires in order to be a valid proposal
sed -i '' 's%"quorum": "0.334000000000000000",%"quorum": "0.000000000000000001",%g' $GAIA_HOME/config/genesis.json
# the minimum proportion of "yes" votes requires for the proposal to pass
sed -i '' 's%"threshold": "0.500000000000000000",%"threshold": "0.000000000000000001",%g' $GAIA_HOME/config/genesis.json
# voting period
sed -i '' 's%"voting_period": "172800s"%"voting_period": "20s"%g' $GAIA_HOME/config/genesis.json
sed -i '' 's%"veto_threshold": "0.334000000000000000",%"veto_threshold": "0.000000000000000001",%g' $GAIA_HOME/config/genesis.json
# min gas prices
sed -i '' 's%"minimum_gas_prices": \[\]%"minimum_gas_prices": [{"denom":"stake", "amount": "0.002"}]%g' $GAIA_HOME/config/genesis.json
cosmovisor run start --home $GAIA_HOME --x-crisis-skip-assert-invariants > gaia.log 2>&1 &
@yaruwangway
Copy link

in run_migration_tests.sh, the withdraw reward will be successful, since it is the bypass-msg.

After this tx, we can also test the MaxTotalBypassMinFeeMsgGasUsage,
change MaxTotalBypassMinFeeMsgGasUsage to a smaller value by gov proposing this json file:

{
  "title": "Global fees Param Change",
  "description": "Update global fees Params",
  "changes": [
    {
      "subspace": "globalfee",
      "key": "MaxTotalBypassMinFeeMsgGasUsage",
      "value": 2000
    }
  ],
  "deposit": "1000000uatom"
}

then submit tx withdraw reward without paying fee, it should fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment