Skip to content

Commit

Permalink
CNS-376: plans/projects to call fixation migration to version 2
Browse files Browse the repository at this point in the history
This migration updates the refcount of head entries (i.e. entry versions that
are most recent), as part of fixing the refcount and delete logic.
  • Loading branch information
orenl-lava committed Apr 13, 2023
1 parent 2cdbedc commit dea157d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
25 changes: 25 additions & 0 deletions x/plans/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type Migrator struct {
keeper Keeper
}

func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate2to3 implements store migration from v2 to v3:
// Trigger the version upgrade of the planFS fixation store
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
keeper := m.keeper
if err := keeper.plansFS.MigrateVersion(ctx); err != nil {
return fmt.Errorf("%w: plans fixation-store", err)
}
return nil
}
11 changes: 9 additions & 2 deletions x/plans/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,16 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
}

// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
// module-specific GRPC queries. It also registers migration handlers.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

migrator := keeper.NewMigrator(am.keeper)

// register v2 -> v3 migration
if err := cfg.RegisterMigration(types.ModuleName, 2, migrator.Migrate2to3); err != nil {
panic(fmt.Errorf("%s: failed to register migration to v3: %w", types.ModuleName, err))
}
}

// RegisterInvariants registers the capability module's invariants.
Expand All @@ -157,7 +164,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 2 }
func (AppModule) ConsensusVersion() uint64 { return 3 }

// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down
28 changes: 28 additions & 0 deletions x/projects/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type Migrator struct {
keeper Keeper
}

func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate2to3 implements store migration from v2 to v3:
// Trigger version upgrade of the projectsFS, develooperKeysFS fixation stores
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
keeper := m.keeper
if err := keeper.projectsFS.MigrateVersion(ctx); err != nil {
return fmt.Errorf("%w: projects fixation-store", err)
}
if err := keeper.developerKeysFS.MigrateVersion(ctx); err != nil {
return fmt.Errorf("%w: developerKeys fixation-store", err)
}
return nil
}
11 changes: 9 additions & 2 deletions x/projects/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,16 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
}

// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
// module-specific GRPC queries. It also registers migration handlers.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)

migrator := keeper.NewMigrator(am.keeper)

// register v2 -> v3 migration
if err := cfg.RegisterMigration(types.ModuleName, 2, migrator.Migrate2to3); err != nil {
panic(fmt.Errorf("%s: failed to register migration to v3: %w", types.ModuleName, err))
}
}

// RegisterInvariants registers the capability module's invariants.
Expand All @@ -158,7 +165,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion implements ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 2 }
func (AppModule) ConsensusVersion() uint64 { return 3 }

// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down

0 comments on commit dea157d

Please sign in to comment.