From 950d2ba2b1eb6c616e9ab99ebbc6a49b65326fdd Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Thu, 12 Dec 2024 14:47:03 +0100 Subject: [PATCH] feat(upgrade): add drs 2 upgrade handler (#396) Co-authored-by: omritoptix Co-authored-by: keruch --- Makefile | 2 +- app/app.go | 68 ++++++++++++++++----------------- app/test_helpers.go | 5 ++- app/upgrades/drs-2/constants.go | 19 +++++++++ app/upgrades/drs-2/upgrade.go | 39 +++++++++++++++++++ app/upgrades/types.go | 29 ++++++++++++++ app/upgrades/v2.2.0/upgrade.go | 16 -------- go.mod | 6 +-- go.sum | 8 ++-- 9 files changed, 132 insertions(+), 60 deletions(-) create mode 100644 app/upgrades/drs-2/constants.go create mode 100644 app/upgrades/drs-2/upgrade.go create mode 100644 app/upgrades/types.go delete mode 100644 app/upgrades/v2.2.0/upgrade.go diff --git a/Makefile b/Makefile index 973e9ae3..2b066573 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 = 1 +DRS_VERSION = 2 #ifndef $(CELESTIA_NETWORK) # CELESTIA_NETWORK=mock diff --git a/app/app.go b/app/app.go index 0a9de573..5dc703d6 100644 --- a/app/app.go +++ b/app/app.go @@ -131,7 +131,6 @@ import ( "github.com/evmos/evmos/v12/ethereum/eip712" ethermint "github.com/evmos/evmos/v12/types" - claimstypes "github.com/evmos/evmos/v12/x/claims/types" "github.com/evmos/evmos/v12/x/erc20" erc20client "github.com/evmos/evmos/v12/x/erc20/client" erc20keeper "github.com/evmos/evmos/v12/x/erc20/keeper" @@ -152,13 +151,15 @@ import ( hubtypes "github.com/dymensionxyz/dymension-rdk/x/hub/types" // Upgrade handlers - v2_2_0_upgrade "github.com/dymensionxyz/rollapp-evm/app/upgrades/v2.2.0" // Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes _ "github.com/ethereum/go-ethereum/eth/tracers/js" _ "github.com/ethereum/go-ethereum/eth/tracers/native" dymintversion "github.com/dymensionxyz/dymint/version" + + "github.com/dymensionxyz/rollapp-evm/app/upgrades" + drs2 "github.com/dymensionxyz/rollapp-evm/app/upgrades/drs-2" ) const ( @@ -183,6 +184,8 @@ var ( feemarkettypes.StoreKey, erc20types.StoreKey, } + // Upgrades contains the upgrade handlers for the application + Upgrades = []upgrades.Upgrade{drs2.Upgrade} ) func getGovProposalHandlers() []govclient.ProposalHandler { @@ -1113,39 +1116,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } -func (app *App) setupUpgradeHandlers() { - UpgradeName := "v2.2.0" - - app.UpgradeKeeper.SetUpgradeHandler( - UpgradeName, - v2_2_0_upgrade.CreateUpgradeHandler( - app.mm, app.configurator, - ), - ) - - // When a planned update height is reached, the old binary will panic - // writing on disk the height and name of the update that triggered it - // This will read that value, and execute the preparations for the upgrade. - upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() - if err != nil { - panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) - } - - // Pre upgrade handler - switch upgradeInfo.Name { - // do nothing - } - - if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - - storeUpgrades := storetypes.StoreUpgrades{ - Deleted: []string{claimstypes.ModuleName}, - } - - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) - } -} - var evmAccountName = proto.MessageName(ðermint.EthAccount{}) func shouldBumpEvmAccountSequence(accountProtoName string, account authtypes.AccountI) (bool, error) { @@ -1160,3 +1130,31 @@ func shouldBumpEvmAccountSequence(accountProtoName string, account authtypes.Acc } return evmAccount.Type() == ethermint.AccountTypeEOA, nil } + +func (app *App) setupUpgradeHandlers() { + for _, u := range Upgrades { + app.setupUpgradeHandler(u) + } +} + +func (app *App) setupUpgradeHandler(upgrade upgrades.Upgrade) { + app.UpgradeKeeper.SetUpgradeHandler( + upgrade.Name, + upgrade.CreateHandler( + app.RollappParamsKeeper, + app.EvmKeeper, + app.mm, + app.configurator, + ), + ) + + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) + } + + if upgradeInfo.Name == upgrade.Name && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + // configure store loader with the store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) + } +} diff --git a/app/test_helpers.go b/app/test_helpers.go index 25d78f7d..89e0887b 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -5,6 +5,8 @@ import ( "testing" "time" + version "github.com/dymensionxyz/dymint/version" + appcodec "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -87,8 +89,8 @@ func SetupWithGenesisValSet(t *testing.T, valSet *types2.ValidatorSet, genAccs [ app, genesisState := setup(true, 5) genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...) + version.DRS = "1" genesisState = setRollappVersion(app.appCodec, genesisState, 1) - denomMD := banktypes.Metadata{ Description: "Stake token", DenomUnits: []*banktypes.DenomUnit{ @@ -121,6 +123,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *types2.ValidatorSet, genAccs [ ConsensusParams: utils.DefaultConsensusParams, AppStateBytes: stateBytes, ChainId: TestChainID, + GenesisChecksum: "abcdef", }, ) diff --git a/app/upgrades/drs-2/constants.go b/app/upgrades/drs-2/constants.go new file mode 100644 index 00000000..f1b446e9 --- /dev/null +++ b/app/upgrades/drs-2/constants.go @@ -0,0 +1,19 @@ +package drs2 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/dymensionxyz/rollapp-evm/app/upgrades" + claimstypes "github.com/evmos/evmos/v12/x/claims/types" +) + +const ( + UpgradeName = "drs-2" +) + +var Upgrade = upgrades.Upgrade{ + Name: UpgradeName, + CreateHandler: CreateUpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{ + Deleted: []string{claimstypes.ModuleName}, + }, +} diff --git a/app/upgrades/drs-2/upgrade.go b/app/upgrades/drs-2/upgrade.go new file mode 100644 index 00000000..137226d7 --- /dev/null +++ b/app/upgrades/drs-2/upgrade.go @@ -0,0 +1,39 @@ +package drs2 + +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" + rollappparamstypes "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types" + evmkeeper "github.com/evmos/evmos/v12/x/evm/keeper" + evmtypes "github.com/evmos/evmos/v12/x/evm/types" +) + +func CreateUpgradeHandler( + rpKeeper rollappparamskeeper.Keeper, + evmKeeper *evmkeeper.Keeper, + mm *module.Manager, + 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 + evmOldParams := evmKeeper.GetParams(ctx) + evmOldParams.GasDenom = evmtypes.DefaultParams().GasDenom + err = evmKeeper.SetParams(ctx, evmOldParams) + if err != nil { + return nil, err + } + return mm.RunMigrations(ctx, configurator, fromVM) + } +} diff --git a/app/upgrades/types.go b/app/upgrades/types.go new file mode 100644 index 00000000..a153c772 --- /dev/null +++ b/app/upgrades/types.go @@ -0,0 +1,29 @@ +package upgrades + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/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" +) + +// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal +// must have written, in order for the state migration to go smoothly. +// An upgrade must implement this struct, and then set it in the app.go. +// The app.go will then define the handler. +type Upgrade struct { + // Upgrade version name, for the upgrade handler, e.g. `v4` + Name string + + // CreateHandler defines the function that creates an upgrade handler + CreateHandler func( + rpKeeper rollappparamskeeper.Keeper, + evmKeeper *evmkeeper.Keeper, + mm *module.Manager, + configurator module.Configurator, + ) upgradetypes.UpgradeHandler + + // Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed. + StoreUpgrades storetypes.StoreUpgrades +} diff --git a/app/upgrades/v2.2.0/upgrade.go b/app/upgrades/v2.2.0/upgrade.go deleted file mode 100644 index 3fbf388a..00000000 --- a/app/upgrades/v2.2.0/upgrade.go +++ /dev/null @@ -1,16 +0,0 @@ -package v2_2_0 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - return mm.RunMigrations(ctx, configurator, fromVM) - } -} diff --git a/go.mod b/go.mod index 4b477808..2bc033e8 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,9 @@ require ( github.com/bcdevtools/evm-block-explorer-rpc-cosmos v1.1.4 github.com/cosmos/cosmos-sdk v0.46.16 github.com/cosmos/ibc-go/v6 v6.2.1 - github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241211172411-14119cc73f17 - github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241208124948-7de4e892a304 + github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd + github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241212094010-b3df828e7611 + github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241210155059-b7f6555f960c github.com/ethereum/go-ethereum v1.12.0 github.com/evmos/evmos/v12 v12.1.6 github.com/gogo/protobuf v1.3.3 @@ -117,7 +118,6 @@ require ( github.com/dop251/goja v0.0.0-20230122112309-96b1610dd4f7 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.5.0 // indirect - github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd // indirect github.com/dymensionxyz/gerr-cosmos v1.0.0 // indirect github.com/dymensionxyz/sdk-utils v0.1.2-0.20240909101947-e1b483ada9c8 // indirect github.com/edsrzf/mmap-go v1.0.0 // indirect diff --git a/go.sum b/go.sum index 0a332d96..8adca6c9 100644 --- a/go.sum +++ b/go.sum @@ -577,10 +577,10 @@ github.com/dymensionxyz/cosmos-sdk v0.46.17-0.20241128210616-e9dfe47b8c73 h1:A0O github.com/dymensionxyz/cosmos-sdk v0.46.17-0.20241128210616-e9dfe47b8c73/go.mod h1:VPUuzF+l+ekSGPV7VVB8m0OMQfwp3QdKWNZjvkU3A1U= github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd h1:V89QyOFM84o9w0iFdctMU6So8SS/Xt32JWAXGqJduT0= github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20241121093220-e0d7ad456fbd/go.mod h1:3weqpVj/TqTFpC0LjEB3H+HZSpm7BrQ1QkEg1Ahy6KY= -github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241211172411-14119cc73f17 h1:D12T30p6UH5ccXbcC2diUAq3RMD3qbw3uBwlzYbfJsw= -github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241211172411-14119cc73f17/go.mod h1:L6vBXdlUPxHFUz3kjWwXdOun0uX3SrsD9KkpxWQkUy4= -github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241208124948-7de4e892a304 h1:qkjoXhCOOVsSpjQ2dOVlyw4vPWdsdCmIZM5jqnOpw6o= -github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241208124948-7de4e892a304/go.mod h1:C3VbfePK85aRCdA1iHzB2AYD+n1gKR9Pw+wm3wQUXvE= +github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241212094010-b3df828e7611 h1:uQuoHQ/q74Sk5hEHviry/34/VRzkbdCBKo9A5gXlMsQ= +github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241212094010-b3df828e7611/go.mod h1:L6vBXdlUPxHFUz3kjWwXdOun0uX3SrsD9KkpxWQkUy4= +github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241210155059-b7f6555f960c h1:y6RSUu2GnWZaV6TRZIZaKRUH6+JTLMWpAPIPXFMWVqM= +github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241210155059-b7f6555f960c/go.mod h1:C3VbfePK85aRCdA1iHzB2AYD+n1gKR9Pw+wm3wQUXvE= github.com/dymensionxyz/evmos/v12 v12.1.7-0.20241212094620-9bc1b171a7f9 h1:ul6uH++328ZvudaX5zTFdp30k34AHkeBYcD7vv79T6I= github.com/dymensionxyz/evmos/v12 v12.1.7-0.20241212094620-9bc1b171a7f9/go.mod h1:CI6D89pkoiIm4BjoMFNnEaCLdKBEobLuwvhS0c1zh7Y= github.com/dymensionxyz/gerr-cosmos v1.0.0 h1:oi91rgOkpJWr41oX9JOyjvvBnhGY54tj513x8VlDAEc=