Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add v22.2.0 upgrade handler #3539

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/v23/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/v23/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
Loading