Skip to content

Commit

Permalink
chore!: add v22.2.0 upgrade handler (#3538)
Browse files Browse the repository at this point in the history
* chore: add v22.2.0 upgrade handler

* fix upgrade script to handle new format
  • Loading branch information
wllmshao authored Feb 13, 2025
1 parent f228765 commit 0cac467
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 25 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
### DEPENDENCIES
- Bump [ibc-apps/middleware/packet-forward-middleware](https://github.com/cosmos/ibc-apps/tree/main/middleware/packet-forward-middleware) to
[v8.1.1](https://github.com/cosmos/ibc-apps/releases/tag/middleware%2Fpacket-forward-middleware%2Fv8.1.1)
([\#3533](https://github.com/cosmos/gaia/pull/3533))
([\#3534](https://github.com/cosmos/gaia/pull/3534))
- Add `v22.2.0` upgrade handler ([\#3538](https://github.com/cosmos/gaia/pull/3538))

### STATE BREAKING

- Bump [ibc-apps/middleware/packet-forward-middleware](https://github.com/cosmos/ibc-apps/tree/main/middleware/packet-forward-middleware) to
[v8.1.1](https://github.com/cosmos/ibc-apps/releases/tag/middleware%2Fpacket-forward-middleware%2Fv8.1.1)
([\#3534](https://github.com/cosmos/gaia/pull/3534))
- Add `v22.2.0` upgrade handler ([\#3538](https://github.com/cosmos/gaia/pull/3538))

## Previous Versions

Expand Down
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ import (
gaiaante "github.com/cosmos/gaia/v22/ante"
"github.com/cosmos/gaia/v22/app/keepers"
"github.com/cosmos/gaia/v22/app/upgrades"
v22 "github.com/cosmos/gaia/v22/app/upgrades/v22"
v22_2_0 "github.com/cosmos/gaia/v22/app/upgrades/v22_2_0"
)

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

Upgrades = []upgrades.Upgrade{v22.Upgrade}
Upgrades = []upgrades.Upgrade{v22_2_0.Upgrade}
)

var (
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/v22_2_0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v22_2_0 //nolint:revive

import (
"github.com/cosmos/gaia/v22/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v22.2.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
}
31 changes: 31 additions & 0 deletions app/upgrades/v22_2_0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package v22_2_0 //nolint:revive

import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/cosmos/gaia/v22/app/keepers"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(c context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)
ctx.Logger().Info("Starting module migrations...")

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("Upgrade v22.2.0 complete")
return vm, nil
}
}
39 changes: 28 additions & 11 deletions contrib/scripts/upgrade_test_scripts/run_gaia.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
#!/bin/sh
#!/bin/bash

set -o errexit -o nounset

# find the highest upgrade version number($UPGRADE_VERSION_NUMBER) within the 'app/upgrades' dir.
# the highest upgrade version is used to propose upgrade and create /cosmovisor/upgrades/$UPGRADE_VERSION/bin dir.
UPGRADES_DIR=$(realpath ./app/upgrades)
UPGRADE_VERSION_NUMBER=0
UPGRADE_VERSION="v0"

version_gt() {
IFS='_' read -ra LEFT_PARTS <<< "${1#v}"
IFS='_' read -ra RIGHT_PARTS <<< "${2#v}"

for ((i=0; i < ${#LEFT_PARTS[@]} || i < ${#RIGHT_PARTS[@]}; i++)); do
LEFT_NUM=${LEFT_PARTS[i]:-0} # Default to 0 if missing
RIGHT_NUM=${RIGHT_PARTS[i]:-0} # Default to 0 if missing

if (( LEFT_NUM > RIGHT_NUM )); then
return 0 # Left is greater
elif (( LEFT_NUM < RIGHT_NUM )); then
return 1 # Right is greater
fi
done

return 1 # Equal versions, so not greater
}

for dir in "$UPGRADES_DIR"/*; do
if [ -d "$dir" ]; then
DIR_NAME=$(basename "$dir")
VERSION_NUMBER="${DIR_NAME#v}"
if [ "$VERSION_NUMBER" -gt "$UPGRADE_VERSION_NUMBER" ]; then
UPGRADE_VERSION_NUMBER=$VERSION_NUMBER

if version_gt "$DIR_NAME" "$UPGRADE_VERSION"; then
UPGRADE_VERSION="$DIR_NAME"
fi
fi
done

if [ -n "$UPGRADE_VERSION_NUMBER" ]; then
echo "Upgrade to version: $UPGRADE_VERSION_NUMBER"
else
echo "No upgrade version found in app/upgrades."
fi
# Convert "_" to "." in the final output
UPGRADE_VERSION="${UPGRADE_VERSION//_/.}"

UPGRADE_VERSION=v$UPGRADE_VERSION_NUMBER
echo "Latest upgrade version: $UPGRADE_VERSION"
NODE_HOME=$(realpath ./build/.gaia)
echo "NODE_HOME = ${NODE_HOME}"
BINARY=$NODE_HOME/cosmovisor/genesis/bin/gaiad
Expand All @@ -41,6 +56,7 @@ rm -rf ./build/.gaia

mkdir -p "$NODE_HOME"/cosmovisor/genesis/bin
cp ./build/gaiadold "$NODE_HOME"/cosmovisor/genesis/bin/gaiad
chmod a+x $BINARY
$BINARY init upgrader --chain-id $CHAINID --home "$NODE_HOME"

if ! test -f "./build/gaiadnew"; then
Expand All @@ -50,6 +66,7 @@ fi

mkdir -p "$NODE_HOME"/cosmovisor/upgrades/$UPGRADE_VERSION/bin
cp ./build/gaiadnew "$NODE_HOME"/cosmovisor/upgrades/$UPGRADE_VERSION/bin/gaiad
chmod a+x "$NODE_HOME"/cosmovisor/upgrades/$UPGRADE_VERSION/bin/gaiad

GOPATH=$(go env GOPATH)

Expand Down
39 changes: 28 additions & 11 deletions contrib/scripts/upgrade_test_scripts/run_upgrade_commands.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
#!/bin/sh
#!/bin/bash

set -o errexit -o nounset

UPGRADES_DIR=$(realpath ./app/upgrades)
UPGRADE_VERSION_NUMBER=0
UPGRADE_VERSION="v0"

version_gt() {
IFS='_' read -ra LEFT_PARTS <<< "${1#v}"
IFS='_' read -ra RIGHT_PARTS <<< "${2#v}"

for ((i=0; i < ${#LEFT_PARTS[@]} || i < ${#RIGHT_PARTS[@]}; i++)); do
LEFT_NUM=${LEFT_PARTS[i]:-0} # Default to 0 if missing
RIGHT_NUM=${RIGHT_PARTS[i]:-0} # Default to 0 if missing

if (( LEFT_NUM > RIGHT_NUM )); then
return 0 # Left is greater
elif (( LEFT_NUM < RIGHT_NUM )); then
return 1 # Right is greater
fi
done

return 1 # Equal versions, so not greater
}

for dir in "$UPGRADES_DIR"/*; do
if [ -d "$dir" ]; then
DIR_NAME=$(basename "$dir")
VERSION_NUMBER="${DIR_NAME#v}"
if [ "$VERSION_NUMBER" -gt "$UPGRADE_VERSION_NUMBER" ]; then
UPGRADE_VERSION_NUMBER=$VERSION_NUMBER

if version_gt "$DIR_NAME" "$UPGRADE_VERSION"; then
UPGRADE_VERSION="$DIR_NAME"
fi
fi
done

if [ -n "$UPGRADE_VERSION_NUMBER" ]; then
echo "Upgrade to version: $UPGRADE_VERSION_NUMBER"
else
echo "No upgrade version found in app/upgrades."
fi
# Convert "_" to "." in the final output
UPGRADE_VERSION="${UPGRADE_VERSION//_/.}"

echo "Latest upgrade version: $UPGRADE_VERSION"

UPGRADE_VERSION=v$UPGRADE_VERSION_NUMBER
UPGRADE_HEIGHT=$1

if [ -z "$1" ]; then
Expand All @@ -35,6 +51,7 @@ echo "NODE_HOME = ${NODE_HOME}"

BINARY=$NODE_HOME/cosmovisor/genesis/bin/gaiad
echo "BINARY = ${BINARY}"
chmod a+x $BINARY

$BINARY version

Expand Down

0 comments on commit 0cac467

Please sign in to comment.