Skip to content

Commit

Permalink
wip: add upgrade handler
Browse files Browse the repository at this point in the history
fix: adjust cudos-noded command for compability with 0.45 and 0.47 sdk
  • Loading branch information
tuantran1702 committed Feb 20, 2024
1 parent 432141e commit 2549da7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
30 changes: 29 additions & 1 deletion app/app_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/authz"

consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

Expand All @@ -21,6 +22,7 @@ func (app *App) SetUpgradeHandlers() {
setHandlerForVersion_1_0(app)
setHandlerForVersion_1_1(app)
setHandlerForVersion_1_2(app)
setHandlerForVersion_1_3(app)
}

func setHandlerForVersion_1_0(app *App) {
Expand Down Expand Up @@ -104,3 +106,29 @@ func setHandlerForVersion_1_2(app *App) {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

func setHandlerForVersion_1_3(app *App) {
const upgradeVersion string = "v1.3"

app.UpgradeKeeper.SetUpgradeHandler(upgradeVersion, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == upgradeVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
crisistypes.ModuleName,
consensustypes.ModuleName,
},
Deleted: []string{},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

}
1 change: 1 addition & 0 deletions cmd/cudos-noded/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
gravitycmd.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
gravitycmd.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
AddGenesisAccountCmd(app.DefaultNodeHome),
debug.Cmd(),
config.Cmd(),
)
Expand Down
9 changes: 5 additions & 4 deletions scripts/run-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ TEST1_ADDRESS=$($BINARY keys show $KEY1 -a --keyring-backend $KEYRING --home $HO
TEST2_ADDRESS=$($BINARY keys show $KEY2 -a --keyring-backend $KEYRING --home $HOME_DIR)

# Allocate genesis accounts (cosmos formatted addresses)
$BINARY genesis add-genesis-account $TEST0_ADDRESS "500000000000000000000000000${DENOM}" --home $HOME_DIR
$BINARY genesis add-genesis-account $TEST1_ADDRESS "500000000000000000000000000${DENOM}" --home $HOME_DIR
$BINARY genesis add-genesis-account $TEST2_ADDRESS "500000000000000000000000000${DENOM}" --home $HOME_DIR
$BINARY add-genesis-account $TEST0_ADDRESS "500000000000000000000000000${DENOM}" --home $HOME_DIR
$BINARY add-genesis-account $TEST1_ADDRESS "500000000000000000000000000${DENOM}" --home $HOME_DIR
$BINARY add-genesis-account $TEST2_ADDRESS "500000000000000000000000000${DENOM}" --home $HOME_DIR

update_test_genesis '.app_state["gov"]["voting_params"]["voting_period"]="50s"'
update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"'
Expand All @@ -81,8 +81,9 @@ update_test_genesis '.app_state["gravity"]["erc20_to_denoms"]=[{"erc20": "'$ERC2
# 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 's/minimum-gas-prices = ""/minimum-gas-prices = "0acudos"/' $HOME_DIR/config/app.toml

# Sign genesis transaction
# Sign genesis transaction
# TEST0 is the validator
$BINARY gentx $KEY "500000000000000000000000${DENOM}" "0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97" $TEST0_ADDRESS --commission-rate=$COMMISSION_RATE --min-self-delegation=$MIN_SELF_DELEGATION --commission-max-rate=$COMMISSION_MAX_RATE --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME_DIR

Expand Down
6 changes: 3 additions & 3 deletions scripts/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# the upgrade is a fork, "true" otherwise
FORK=${FORK:-"false"}

OLD_VERSION=v1.1.0
OLD_VERSION=v1.2.0
UPGRADE_WAIT=${UPGRADE_WAIT:-20}
HOME=cudos-data
ROOT=$(pwd)
DENOM=acudos
CHAIN_ID=cudos-node
SOFTWARE_UPGRADE_NAME="v1.2"
SOFTWARE_UPGRADE_NAME="v1.3"
ADDITIONAL_PRE_SCRIPTS=${ADDITIONAL_PRE_SCRIPTS:-""}
ADDITIONAL_AFTER_SCRIPTS=${ADDITIONAL_AFTER_SCRIPTS:-""}
NEW_VERSION=v1.2.0
NEW_VERSION=v1.3.0
if [[ "$FORK" == "true" ]]; then
export cudos-noded_HALT_HEIGHT=20
fi
Expand Down

0 comments on commit 2549da7

Please sign in to comment.