Skip to content

Commit

Permalink
refactor: use major version in release upgrade handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Nov 14, 2024
1 parent 07120f1 commit d1182f7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
23 changes: 20 additions & 3 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/zeta-chain/node/pkg/constant"
"golang.org/x/mod/semver"
)

// GetDefaultUpgradeHandlerVersion prints the default upgrade handler version
//
// There may be multiple upgrade handlers configured on some releases if different
// migrations needto be run in different environment
func GetDefaultUpgradeHandlerVersion() string {
// development builds always use the full version in the release handlers
if semver.Build(constant.Version) != "" || semver.Prerelease(constant.Version) != "" {
return constant.Version
}

// release builds use just the major version (v22.0.0 -> v22)
return semver.Major(constant.Version)
}

func SetupHandlers(app *App) {
allUpgrades := upgradeTracker{
upgrades: []upgradeTrackerItem{
Expand Down Expand Up @@ -50,10 +65,12 @@ func SetupHandlers(app *App) {
upgradeHandlerFns, storeUpgrades = allUpgrades.mergeAllUpgrades()
}

upgradeHandlerVersion := GetDefaultUpgradeHandlerVersion()

app.UpgradeKeeper.SetUpgradeHandler(
constant.Version,
upgradeHandlerVersion,
func(ctx sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + constant.Version)
app.Logger().Info("Running upgrade handler for " + upgradeHandlerVersion)

var err error
for _, upgradeHandler := range upgradeHandlerFns {
Expand All @@ -71,7 +88,7 @@ func SetupHandlers(app *App) {
if err != nil {
panic(err)
}
if upgradeInfo.Name == constant.Version && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
if upgradeInfo.Name == upgradeHandlerVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
// so that new stores start with the correct version (the current height of chain),
Expand Down
1 change: 1 addition & 0 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig types.EncodingConfig) {
GetPubKeyCmd(),
CollectObserverInfoCmd(),
AddrConversionCmd(),
UpgradeHandlerVersionCmd(),
tmcli.NewCompletionCmd(rootCmd, true),
ethermintclient.NewTestnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),

Expand Down
18 changes: 18 additions & 0 deletions cmd/zetacored/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"

"github.com/spf13/cobra"
"github.com/zeta-chain/node/app"
)

func UpgradeHandlerVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "upgrade-handler-version",
Short: "Print the upgrade handler version",
Run: func(cmd *cobra.Command, args []string) {

Check failure on line 14 in cmd/zetacored/version.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
fmt.Println(app.GetDefaultUpgradeHandlerVersion())
},
}
}
2 changes: 1 addition & 1 deletion contrib/localnet/scripts/start-upgrade-orchestrator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fi
# get new zetacored version
curl -L -o /tmp/zetacored.new "${ZETACORED_URL}"
chmod +x /tmp/zetacored.new
UPGRADE_NAME=$(/tmp/zetacored.new version)
UPGRADE_NAME=$(/tmp/zetacored.new upgrade-handler-version)

# if explicit upgrade height not provided, use dumb estimator
if [[ -z $UPGRADE_HEIGHT ]]; then
Expand Down

0 comments on commit d1182f7

Please sign in to comment.