From 6fb64cafa758d8b3a1b0df9fb2625b8fefcefb99 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Thu, 14 Nov 2024 11:59:19 -0800 Subject: [PATCH] refactor: use major version in release upgrade handlers (#3159) * refactor: use major version in release upgrade handlers * use + rather than - for semver compliance * fmt * docs * fix lint * more semver 2.0 compliance * remove check-upgrade-handler-updated --- .github/workflows/publish-release.yml | 33 ------------------- app/setup_handlers.go | 26 +++++++++++++-- cmd/zetacored/root.go | 1 + cmd/zetacored/version.go | 19 +++++++++++ .../scripts/start-upgrade-orchestrator.sh | 2 +- docs/cli/zetacored/cli.md | 29 ++++++++++++++++ version.sh | 4 +-- 7 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 cmd/zetacored/version.go diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index a8b324de6b..924706af29 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -94,38 +94,6 @@ jobs: run: | echo "continue" - check-upgrade-handler-updated: - needs: - - check-branch - runs-on: ubuntu-22.04 - timeout-minutes: 10 - steps: - - - uses: actions/checkout@v4 - if: inputs.skip_checks != true - with: - fetch-depth: 0 - - - name: Major Version in Upgrade Handler Must Match Tag - if: inputs.skip_checks != true - run: | - UPGRADE_HANDLER_MAJOR_VERSION=$(cat app/setup_handlers.go | grep "const releaseVersion" | cut -d ' ' -f4 | tr -d '"' | cut -d '.' -f 1 | tr -d '\n') - USER_INPUT_VERSION=$(echo "${{ inputs.version }}" | cut -d '.' -f 1 | tr -d '\n') - echo "Upgrade Handler Major Version: ${UPGRADE_HANDLER_MAJOR_VERSION}" - echo "User Inputted Release Version: ${USER_INPUT_VERSION}" - if [ ${USER_INPUT_VERSION} != $UPGRADE_HANDLER_MAJOR_VERSION ]; then - echo "ERROR: The input version doesn't match the release handler for the branch selected. Please ensure the upgrade handler of the branch you selected when you ran the pipeline matches the input version." - echo "Did you forget to update the 'releaseVersion' in app/setup_handlers.go?" - exit 1 - fi - echo "The major version found in 'releaseVersion' in app/setup_handlers.go matches this tagged release - Moving Forward!" - - - name: Mark Job Complete Skipped - if: inputs.skip_checks == true - shell: bash - run: | - echo "continue" - publish-release: permissions: id-token: write @@ -134,7 +102,6 @@ jobs: if: inputs.skip_release != true needs: - check-changelog - - check-upgrade-handler-updated - check-branch - check-goreleaser runs-on: ${{ vars.RELEASE_RUNNER }} diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 04a94da668..1468f83fe2 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -7,10 +7,28 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "golang.org/x/mod/semver" "github.com/zeta-chain/node/pkg/constant" ) +// 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 { + // semver must have v prefix, but we store without prefix + vVersion := "v" + constant.Version + + // development builds always use the full version in the release handlers + if semver.Build(vVersion) != "" || semver.Prerelease(vVersion) != "" { + return constant.Version + } + + // release builds use just the major version (v22.0.0 -> v22) + return semver.Major(vVersion) +} + func SetupHandlers(app *App) { allUpgrades := upgradeTracker{ upgrades: []upgradeTrackerItem{ @@ -50,10 +68,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 { @@ -71,7 +91,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), diff --git a/cmd/zetacored/root.go b/cmd/zetacored/root.go index 93ae4ba469..1f7115e57a 100644 --- a/cmd/zetacored/root.go +++ b/cmd/zetacored/root.go @@ -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{}), diff --git a/cmd/zetacored/version.go b/cmd/zetacored/version.go new file mode 100644 index 0000000000..d9da8ac484 --- /dev/null +++ b/cmd/zetacored/version.go @@ -0,0 +1,19 @@ +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 default upgrade handler version", + Run: func(_ *cobra.Command, _ []string) { + fmt.Println(app.GetDefaultUpgradeHandlerVersion()) + }, + } +} diff --git a/contrib/localnet/scripts/start-upgrade-orchestrator.sh b/contrib/localnet/scripts/start-upgrade-orchestrator.sh index 1f8089bc3d..13d09a447f 100755 --- a/contrib/localnet/scripts/start-upgrade-orchestrator.sh +++ b/contrib/localnet/scripts/start-upgrade-orchestrator.sh @@ -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 diff --git a/docs/cli/zetacored/cli.md b/docs/cli/zetacored/cli.md index d7a594d94f..96c6e71510 100644 --- a/docs/cli/zetacored/cli.md +++ b/docs/cli/zetacored/cli.md @@ -39,6 +39,7 @@ Zetacore Daemon (server) * [zetacored tendermint](#zetacored-tendermint) - Tendermint subcommands * [zetacored testnet](#zetacored-testnet) - subcommands for starting or configuring local testnets * [zetacored tx](#zetacored-tx) - Transactions subcommands +* [zetacored upgrade-handler-version](#zetacored-upgrade-handler-version) - Print the default upgrade handler version * [zetacored validate-genesis](#zetacored-validate-genesis) - validates the genesis file at the default location or at the location passed as an arg * [zetacored version](#zetacored-version) - Print the application binary version information @@ -14346,6 +14347,34 @@ zetacored tx vesting create-vesting-account [to_address] [amount] [end_time] [fl * [zetacored tx vesting](#zetacored-tx-vesting) - Vesting transaction subcommands +## zetacored upgrade-handler-version + +Print the default upgrade handler version + +``` +zetacored upgrade-handler-version [flags] +``` + +### Options + +``` + -h, --help help for upgrade-handler-version +``` + +### Options inherited from parent commands + +``` + --home string directory for config and data + --log_format string The logging format (json|plain) + --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) + --log_no_color Disable colored logs + --trace print out full stack trace on errors +``` + +### SEE ALSO + +* [zetacored](#zetacored) - Zetacore Daemon (server) + ## zetacored validate-genesis validates the genesis file at the default location or at the location passed as an arg diff --git a/version.sh b/version.sh index aedbfa5eeb..002f5cc990 100755 --- a/version.sh +++ b/version.sh @@ -22,8 +22,8 @@ short_commit=$(git rev-parse --short HEAD) # append -dirty for dirty builds if ! git diff --no-ext-diff --quiet --exit-code ; then - echo "0.0.${commit_timestamp}-${short_commit}-dirty" + echo "0.0.${commit_timestamp}+${short_commit}.dirty" exit fi -echo "0.0.${commit_timestamp}-${short_commit}" \ No newline at end of file +echo "0.0.${commit_timestamp}+${short_commit}" \ No newline at end of file