Skip to content

Commit

Permalink
[CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade …
Browse files Browse the repository at this point in the history
…handler.

This adds the 3.0.0-dev0 binaries statically and fixes the IBC parameter space to map the old parameters to the new ones allowing for the IBC upgrade as per the upgrade guide
(https://github.com/cosmos/ibc-go/blob/e3e8f343d05d3f7dfd958877562bca3aff89b758/docs/docs/05-migrations/11-v7-to-v8.md#params-migration) and this sample
(https://github.com/cosmos/ibc-go/blob/v8.0.0/testing/simapp/app.go#L1007-L1012).

It turns out that the upgrade handlers are already routable and the existing logic could be removed safely without requiring a replacement.

Decided to allow for using the existing upgrade messages to allow the maximum flexibility when doing the release and punted deprecation till once users are on Cosmos 0.50 for some time.

Finally, delete the 3.0.0 upgrade handler.
  • Loading branch information
lcwik committed Jan 5, 2024
1 parent 7e793b6 commit 2d52be9
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 288 deletions.
15 changes: 10 additions & 5 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // nolint:staticcheck
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -511,8 +513,6 @@ func New(
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
/** TODO(CORE-538): Migrate software upgrade type to Cosmos 0.50.
.AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) */
govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:
Expand Down Expand Up @@ -1621,9 +1621,14 @@ func initParamsKeeper(
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)

// register the key tables for legacy param subspaces
keyTable := ibcclient.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())

return paramsKeeper
}
Expand Down
4 changes: 2 additions & 2 deletions protocol/app/msgs/normal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ var (
"/ibc.core.client.v1.MsgRecoverClientResponse": nil,
"/ibc.core.client.v1.MsgSubmitMisbehaviour": &ibcclient.MsgSubmitMisbehaviour{}, //nolint:staticcheck
"/ibc.core.client.v1.MsgSubmitMisbehaviourResponse": nil,
// TODO(CORE-538): Move MsgUpdateClient and MsgUpgradeClient to unsupported_msgs once upgrade has been added
// and verified to function.
// TODO(CORE-851): Move MsgUpdateClient and MsgUpgradeClient to unsupported_msgs once v4.0.0 upgrade has
// been completed and Cosmos 0.50 performs well.
"/ibc.core.client.v1.MsgUpdateClient": &ibcclient.MsgUpdateClient{},
"/ibc.core.client.v1.MsgUpdateClientResponse": nil,
"/ibc.core.client.v1.MsgUpgradeClient": &ibcclient.MsgUpgradeClient{},
Expand Down
13 changes: 6 additions & 7 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
v3_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v3.0.0"
v4_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v4.0.0"
)

var (
// `Upgrades` defines the upgrade handlers and store loaders for the application.
// New upgrades should be added to this slice after they are implemented.
Upgrades = []upgrades.Upgrade{
v3_0_0.Upgrade,
v4_0_0.Upgrade,
}
Forks = []upgrades.Fork{}
)

// setupUpgradeHandlers registers the upgrade handlers to perform custom upgrade
// logic and state migrations for software upgrades.
func (app *App) setupUpgradeHandlers() {
if app.UpgradeKeeper.HasHandler(v3_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v3_0_0.UpgradeName))
if app.UpgradeKeeper.HasHandler(v4_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v4_0_0.UpgradeName))
}
app.UpgradeKeeper.SetUpgradeHandler(
v3_0_0.UpgradeName,
v3_0_0.CreateUpgradeHandler(
v4_0_0.UpgradeName,
v4_0_0.CreateUpgradeHandler(
app.ModuleManager,
app.configurator,
app.AccountKeeper,
),
)
}
Expand Down
22 changes: 0 additions & 22 deletions protocol/app/upgrades/v3.0.0/constants.go

This file was deleted.

169 changes: 0 additions & 169 deletions protocol/app/upgrades/v3.0.0/upgrade.go

This file was deleted.

26 changes: 0 additions & 26 deletions protocol/app/upgrades/v3.0.0/upgrade_test.go

This file was deleted.

28 changes: 28 additions & 0 deletions protocol/app/upgrades/v4.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v_4_0_0

import (
store "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
)

const (
UpgradeName = "v4.0.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
// Add circuittypes as per 0.47 to 0.50 upgrade handler
// https://github.com/cosmos/cosmos-sdk/blob/b7d9d4c8a9b6b8b61716d2023982d29bdc9839a6/simapp/upgrades.go#L21
circuittypes.ModuleName,

// Add new ICA stores that are needed by ICA host types as of v8.
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,
},
},
}
22 changes: 22 additions & 0 deletions protocol/app/upgrades/v4.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v_4_0_0

import (
"context"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName))

return mm.RunMigrations(ctx, configurator, vm)
}
}
1 change: 1 addition & 0 deletions protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
cosmossdk.io/log v1.2.1
cosmossdk.io/store v1.0.0
cosmossdk.io/tools/confix v0.1.0
cosmossdk.io/x/circuit v0.1.0
cosmossdk.io/x/evidence v0.1.0
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/tx v0.12.0
Expand Down
1 change: 1 addition & 0 deletions protocol/testing/containertest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM dydxprotocol-base

COPY ./testing/containertest/dydxprotocold_preupgrade* /bin/
COPY ./testing/containertest/containertest.sh /dydxprotocol/containertest.sh
COPY ./testing/containertest/preupgrade_entrypoint.sh /dydxprotocol/preupgrade_entrypoint.sh
COPY ./testing/containertest/preupgrade_genesis.json /dydxprotocol/preupgrade_genesis.json
Expand Down
Loading

0 comments on commit 2d52be9

Please sign in to comment.