Skip to content

Commit

Permalink
Merge pull request #161 from Fairblock/add-pep-migration
Browse files Browse the repository at this point in the history
Add pep module v1 to v2 migration
  • Loading branch information
p0p3yee committed Jul 31, 2024
2 parents bf0545d + 5d0a44a commit a64ba4a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
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

0 comments on commit a64ba4a

Please sign in to comment.