Skip to content

Commit

Permalink
feat(cosmos): use x/vbank ConsensusVersion to upgrade monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 19, 2024
1 parent 1687747 commit 0e367d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion golang/cosmos/x/vbank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (k Keeper) IsAllowedMonitoringAccount(ctx sdk.Context, addr sdk.AccAddress)
}

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, &params)
k.paramSpace.GetParamSetIfExists(ctx, &params)
return params
}

Expand Down
30 changes: 30 additions & 0 deletions golang/cosmos/x/vbank/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package keeper

import (
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Migrator handles in-place store migrations.
type Migrator struct {
keeper Keeper
}

// NewMigrator creates a new Migrator based on the keeper.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
params := m.keeper.GetParams(ctx)
if params.AllowedMonitoringAccounts != nil {
return nil
}

defaultParams := types.DefaultParams()
params.AllowedMonitoringAccounts = defaultParams.AllowedMonitoringAccounts
m.keeper.SetParams(ctx, params)

return nil
}
8 changes: 7 additions & 1 deletion golang/cosmos/x/vbank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (AppModule) Name() string {
return ModuleName
}

func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }

// BeginBlock implements the AppModule interface
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
Expand Down Expand Up @@ -204,6 +204,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
tx := &types.UnimplementedMsgServer{}
types.RegisterMsgServer(cfg.MsgServer(), tx)
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

m := keeper.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
if err != nil {
panic(err)
}
}

// InitGenesis performs genesis initialization for the ibc-transfer module. It returns
Expand Down

0 comments on commit 0e367d3

Please sign in to comment.