diff --git a/Makefile b/Makefile index 2b06657..aa72709 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/app/app.go b/app/app.go index 5dc703d..4dd4502 100644 --- a/app/app.go +++ b/app/app.go @@ -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 ( @@ -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 { diff --git a/app/upgrades/drs-2/upgrade.go b/app/upgrades/drs-2/upgrade.go index 7846c35..ad866dd 100644 --- a/app/upgrades/drs-2/upgrade.go +++ b/app/upgrades/drs-2/upgrade.go @@ -16,23 +16,35 @@ 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 { + // upgrade drs to 2 + if err := rpKeeper.SetVersion(ctx, uint32(2)); 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 + if err := rpKeeper.SetMinGasPrices(ctx, rollappparamstypes.DefaultParams().MinGasPrices); 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 +} diff --git a/app/upgrades/drs-3/constants.go b/app/upgrades/drs-3/constants.go new file mode 100644 index 0000000..21af7af --- /dev/null +++ b/app/upgrades/drs-3/constants.go @@ -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{}, +} diff --git a/app/upgrades/drs-3/upgrade.go b/app/upgrades/drs-3/upgrade.go new file mode 100644 index 0000000..6e880e8 --- /dev/null +++ b/app/upgrades/drs-3/upgrade.go @@ -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) + } +}