Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pep module v1 to v2 migration #161

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions x/pep/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper

import (
v2 "github.com/Fairblock/fairyring/x/pep/migrations/v2"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
}
33 changes: 33 additions & 0 deletions x/pep/migrations/v2/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package v2

import (
"cosmossdk.io/core/store"
"github.com/Fairblock/fairyring/x/pep/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// MigrateStore migrates the x/pep module state from the consensus version 1 to version 2.
func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, cdc codec.BinaryCodec) error {
currParams := types.NewParams(
[]string{"fairy1yhpqdugfmfuhlvekkurnkstf2vl82063ajmfe5", "fairy1r6q07ne3deq64ezcjwkedcfe6669f0ewpwnxy9"},
[]*types.TrustedCounterParty{
{
ClientId: "07-tendermint-0",
ConnectionId: "connection-0",
ChannelId: "channel-1",
},
},
types.DefaultKeyshareChannelID,
&types.DefaultMinGasPrice,
true,
)

bz, err := cdc.Marshal(&currParams)
if err != nil {
return err
}

store := storeService.OpenKVStore(ctx)
return store.Set(types.ParamsKey, bz)
}
6 changes: 5 additions & 1 deletion x/pep/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
)

// ConsensusVersion defines the current x/pep module consensus version.
const ConsensusVersion = 1
const ConsensusVersion = 2

// ----------------------------------------------------------------------------
// AppModuleBasic
Expand Down Expand Up @@ -154,6 +154,10 @@ func NewAppModule(
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := keeper.NewMigrator(am.keeper)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Errorf("failed to migrate x/%s from version 1 to 2: %w", types.ModuleName, err))
}
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand Down