Skip to content

Commit

Permalink
feaat: add upgrade handler for drs3 (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Dec 16, 2024
1 parent 1b6fb9d commit 62943f4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import (
// Upgrade handlers
"github.com/dymensionxyz/rollapp-wasm/app/upgrades"
drs2 "github.com/dymensionxyz/rollapp-wasm/app/upgrades/drs-2"
drs3 "github.com/dymensionxyz/rollapp-wasm/app/upgrades/drs-3"
)

const (
Expand All @@ -187,7 +188,7 @@ var (
rollappparamstypes.StoreKey,
}
// Upgrades contains the upgrade handlers for the application
Upgrades = []upgrades.Upgrade{drs2.Upgrade}
Upgrades = []upgrades.Upgrade{drs2.Upgrade, drs3.Upgrade}
)

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down
15 changes: 9 additions & 6 deletions app/upgrades/drs-2/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ func CreateUpgradeHandler(
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
//migrate rollapp params with missing min-gas-prices and updating drs to 2
err := rpKeeper.SetVersion(ctx, uint32(2))
if err != nil {
// upgrade drs to 2
if err := rpKeeper.SetVersion(ctx, uint32(2)); err != nil {
return nil, err
}
err = rpKeeper.SetMinGasPrices(ctx, rollappparamstypes.DefaultParams().MinGasPrices)
if err != nil {

if err := HandleUpgrade(ctx, rpKeeper); err != nil {
return nil, err
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}

func HandleUpgrade(ctx sdk.Context, rpKeeper rollappparamskeeper.Keeper) error {
// migrate rollapp params with missing min-gas-prices
return rpKeeper.SetMinGasPrices(ctx, rollappparamstypes.DefaultParams().MinGasPrices)
}
17 changes: 17 additions & 0 deletions app/upgrades/drs-3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package drs3

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"

"github.com/dymensionxyz/rollapp-wasm/app/upgrades"
)

const (
UpgradeName = "drs-3"
)

var Upgrade = upgrades.Upgrade{
Name: UpgradeName,
CreateHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}
30 changes: 30 additions & 0 deletions app/upgrades/drs-3/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package drs3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
rollappparamskeeper "github.com/dymensionxyz/dymension-rdk/x/rollappparams/keeper"

drs2 "github.com/dymensionxyz/rollapp-wasm/app/upgrades/drs-2"
)

func CreateUpgradeHandler(
rpKeeper rollappparamskeeper.Keeper,
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if rpKeeper.GetParams(ctx).DrsVersion == 1 {
// first run drs-2 migration
if err := drs2.HandleUpgrade(ctx, rpKeeper); err != nil {
return nil, err
}
}
// upgrade drs to 3
if err := rpKeeper.SetVersion(ctx, uint32(3)); err != nil {
return nil, err
}
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

0 comments on commit 62943f4

Please sign in to comment.