Skip to content

Commit

Permalink
Add DRS3 upgrade handler
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 committed Dec 16, 2024
1 parent 1d691fc commit bfe42a4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PROJECT_NAME=rollappd
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
DRS_VERSION = 2
DRS_VERSION = 3

#ifndef $(CELESTIA_NETWORK)
# CELESTIA_NETWORK=mock
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ import (

"github.com/dymensionxyz/rollapp-evm/app/upgrades"
drs2 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-2"
drs3 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-3"
)

const (
Expand All @@ -185,7 +186,7 @@ var (
erc20types.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
43 changes: 28 additions & 15 deletions app/upgrades/drs-2/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,36 @@ 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 {
return nil, err
}
err = rpKeeper.SetMinGasPrices(ctx, rollappparamstypes.DefaultParams().MinGasPrices)
if err != nil {
return nil, err
}
//migrate evm params with missing gasDenom
evmParams := evmKeeper.GetParams(ctx)
evmParams.GasDenom = evmParams.EvmDenom
err = evmKeeper.SetParams(ctx, evmParams)
if err != nil {
if err := HandleUpgrade(ctx, rpKeeper, evmKeeper); err != nil {
return nil, err
}
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

func HandleUpgrade(
ctx sdk.Context,
rpKeeper rollappparamskeeper.Keeper,
evmKeeper *evmkeeper.Keeper,
) error {
// migrate rollapp params with missing min-gas-prices and updating drs to 2
err := rpKeeper.SetVersion(ctx, uint32(2))
if err != nil {
return err
}

err = rpKeeper.SetMinGasPrices(ctx, rollappparamstypes.DefaultParams().MinGasPrices)
if err != nil {
return err
}

// migrate evm params with missing gasDenom
evmParams := evmKeeper.GetParams(ctx)
evmParams.GasDenom = evmParams.EvmDenom

if err = evmKeeper.SetParams(ctx, evmParams); err != nil {
return err
}

return nil
}
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-evm/app/upgrades"
)

const (
UpgradeName = "drs-3"
)

var Upgrade = upgrades.Upgrade{
Name: UpgradeName,
CreateHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}
33 changes: 33 additions & 0 deletions app/upgrades/drs-3/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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"
evmkeeper "github.com/evmos/evmos/v12/x/evm/keeper"

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

func CreateUpgradeHandler(
rpKeeper rollappparamskeeper.Keeper,
evmKeeper *evmkeeper.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, evmKeeper); err != nil {
return nil, err
}
}
// upgrade drs to 3
err := rpKeeper.SetVersion(ctx, uint32(3))
if err != nil {
return nil, err
}
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

0 comments on commit bfe42a4

Please sign in to comment.