Skip to content

Commit

Permalink
feat(upgrade): add drs 2 upgrade handler (#396)
Browse files Browse the repository at this point in the history
Co-authored-by: omritoptix <[email protected]>
Co-authored-by: keruch <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 6555be4 commit 950d2ba
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 60 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 = 1
DRS_VERSION = 2

#ifndef $(CELESTIA_NETWORK)
# CELESTIA_NETWORK=mock
Expand Down
68 changes: 33 additions & 35 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand All @@ -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 {
Expand Down Expand Up @@ -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(&ethermint.EthAccount{})

func shouldBumpEvmAccountSequence(accountProtoName string, account authtypes.AccountI) (bool, error) {
Expand All @@ -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))
}
}
5 changes: 4 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -121,6 +123,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *types2.ValidatorSet, genAccs [
ConsensusParams: utils.DefaultConsensusParams,
AppStateBytes: stateBytes,
ChainId: TestChainID,
GenesisChecksum: "abcdef",
},
)

Expand Down
19 changes: 19 additions & 0 deletions app/upgrades/drs-2/constants.go
Original file line number Diff line number Diff line change
@@ -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},
},
}
39 changes: 39 additions & 0 deletions app/upgrades/drs-2/upgrade.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
29 changes: 29 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 0 additions & 16 deletions app/upgrades/v2.2.0/upgrade.go

This file was deleted.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 950d2ba

Please sign in to comment.