Skip to content

Commit

Permalink
feat(app): add v2.2.0 upgrade handler (#248)
Browse files Browse the repository at this point in the history
Co-authored-by: Trinity <[email protected]>
Co-authored-by: Omri <[email protected]>
  • Loading branch information
3 people committed May 15, 2024
1 parent 5bb0cfc commit cc743fe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -131,6 +132,9 @@ import (
"github.com/evmos/evmos/v12/x/ibc/transfer"
transferkeeper "github.com/evmos/evmos/v12/x/ibc/transfer/keeper"

// 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"
Expand Down Expand Up @@ -720,6 +724,7 @@ func NewRollapp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setupUpgradeHandlers()

maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))
h := ante.MustCreateHandler(
Expand Down Expand Up @@ -1025,3 +1030,31 @@ 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) {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storetypes.StoreUpgrades{}))
}
}
16 changes: 16 additions & 0 deletions app/upgrades/v2.2.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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)
}
}

0 comments on commit cc743fe

Please sign in to comment.