Skip to content

Commit

Permalink
refactor: use major version in release upgrade handlers (#3159)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gartnera authored Nov 14, 2024
1 parent 0b6addd commit 6fb64ca
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
26 changes: 23 additions & 3 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
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
19 changes: 19 additions & 0 deletions cmd/zetacored/version.go
Original file line number Diff line number Diff line change
@@ -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())
},
}
}
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
29 changes: 29 additions & 0 deletions docs/cli/zetacored/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
echo "0.0.${commit_timestamp}+${short_commit}"

0 comments on commit 6fb64ca

Please sign in to comment.