Skip to content

Commit

Permalink
Handler for 0.1->0.2 upgrade (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckychess authored Dec 11, 2024
1 parent b5af954 commit aed673f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ RUN make build
FROM golang:${GO_VERSION}-alpine3.20

COPY --from=build-env /root/build/sscd /usr/bin/
COPY --from=build-env /root/start.sh /root/

RUN apk add gcompat bash curl

Expand All @@ -25,4 +24,4 @@ EXPOSE 26657
EXPOSE 1317
EXPOSE 9090

CMD ["bash","/root/start.sh"]
CMD ["sscd", "start"]
23 changes: 18 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import (
"github.com/cosmos/ibc-go/modules/capability"
ibccapabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ibccapabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"github.com/spf13/cast"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward"
Expand Down Expand Up @@ -136,6 +137,8 @@ import (
gmpmodulekeeper "github.com/sagaxyz/ssc/x/gmp/keeper"
gmpmoduletypes "github.com/sagaxyz/ssc/x/gmp/types"

upgrade02 "github.com/sagaxyz/ssc/app/upgrades/0.2"

// this line is used by starport scaffolding # stargate/app/moduleImport

ante "github.com/sagaxyz/ssc/app/ante"
Expand Down Expand Up @@ -1064,6 +1067,8 @@ func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config)
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

keyTable := ibcclienttypes.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
Expand All @@ -1072,10 +1077,10 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
paramsKeeper.Subspace(sscmoduletypes.ModuleName)
paramsKeeper.Subspace(gmpmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace
Expand All @@ -1094,7 +1099,8 @@ func (app *App) ModuleManager() *module.Manager {
}

func (app *App) RegisterUpgradeHandlers() {
//app.UpgradeKeeper.SetUpgradeHandler(upgrade1.Name, upgrade1.UpgradeHandler(app.mm, app.configurator, app.ParamsKeeper, &app.ConsensusParamsKeeper))
baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
app.UpgradeKeeper.SetUpgradeHandler(upgrade02.Name, upgrade02.UpgradeHandler(app.mm, app.configurator, app.ParamsKeeper, &app.ConsensusParamsKeeper, app.IBCKeeper.ClientKeeper, baseAppLegacySS))

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
Expand All @@ -1106,6 +1112,13 @@ func (app *App) RegisterUpgradeHandlers() {
}
var storeUpgrades *storetypes.StoreUpgrades
switch upgradeInfo.Name {
case upgrade02.Name:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{
gmpmoduletypes.StoreKey,
packetforwardtypes.StoreKey,
},
}
default:
}
if storeUpgrades != nil {
Expand Down
32 changes: 32 additions & 0 deletions app/upgrades/0.2/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package v02

import (
"context"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibcclientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
)

const Name = "0.1-to-0.2"

func UpgradeHandler(mm *module.Manager, configurator module.Configurator, paramsKeeper paramskeeper.Keeper, consensusKeeper *consensuskeeper.Keeper, clientKeeper ibcclientkeeper.Keeper, baseAppLegacySS paramstypes.Subspace) upgradetypes.UpgradeHandler {
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
cp := baseapp.GetConsensusParams(sdkCtx, baseAppLegacySS)
if cp == nil {
return nil, fmt.Errorf("consensus parameters are undefined")
}
err := consensusKeeper.ParamsStore.Set(ctx, *cp)
if err != nil {
return nil, fmt.Errorf("failed to set consensus params: %w", err)
}
return mm.RunMigrations(ctx, configurator, vm)
}
}
18 changes: 0 additions & 18 deletions app/upgrades/v1/upgrades.go

This file was deleted.

0 comments on commit aed673f

Please sign in to comment.