Skip to content

Commit

Permalink
Merge pull request #550 from lavanet/CNS-fixation-migration-3To4
Browse files Browse the repository at this point in the history
CNS-fixation-migration
  • Loading branch information
Yaroms authored Jun 12, 2023
2 parents 1ccbfa2 + 43edb5b commit 9a045e9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ var Upgrades = []upgrades.Upgrade{
upgrades.Upgrade_0_12_0,
upgrades.Upgrade_0_12_1,
upgrades.Upgrade_0_13_0,
upgrades.Upgrade_0_13_1,
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ var Upgrade_0_13_0 = Upgrade{
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

var Upgrade_0_13_1 = Upgrade{
UpgradeName: "v0.13.1",
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
9 changes: 9 additions & 0 deletions common/fixation_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var fixationMigrators = map[int]func(sdk.Context, *FixationStore) error{
// MigrateVerrsion performs pending internal version migration(s), if any.
func (fs *FixationStore) MigrateVersion(ctx sdk.Context) (err error) {
from := fs.getVersion(ctx)
return fs.MigrateVersionFrom(ctx, from)
}

func (fs *FixationStore) MigrateVersionFrom(ctx sdk.Context, from uint64) (err error) {
to := FixationVersion()

for from < to {
Expand Down Expand Up @@ -169,6 +173,8 @@ func fixationMigrate3to4(ctx sdk.Context, fs *FixationStore) error {
return fmt.Errorf("%s: failed to sanitize index: %s", fs.prefixForErrors(1), index)
}

fs.setEntryIndex(ctx, safeIndex, true)

blocks := fs.GetAllEntryVersions(ctx, index)
if len(blocks) < 1 {
return fmt.Errorf("%s: no versions for index: %s", fs.prefixForErrors(1), index)
Expand All @@ -184,6 +190,9 @@ func fixationMigrate3to4(ctx sdk.Context, fs *FixationStore) error {
key := encodeForTimer(entry.Index, entry.Block, timerStaleEntry)
fs.tstore.AddTimerByBlockHeight(ctx, entry.StaleAt, key, []byte{})
}

entry.DeleteAt = math.MaxUint64
fs.setEntry(ctx, entry)
}
}

Expand Down
15 changes: 0 additions & 15 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31339,9 +31339,6 @@ paths:
subscription:
type: string
title: the subscription address that owns the project
description:
type: string
title: the description of the project for the users convinient
enabled:
type: boolean
title: enabled flag
Expand Down Expand Up @@ -31468,9 +31465,6 @@ paths:
subscription:
type: string
title: the subscription address that owns the project
description:
type: string
title: the description of the project for the users convinient
enabled:
type: boolean
title: enabled flag
Expand Down Expand Up @@ -56009,9 +56003,6 @@ definitions:
subscription:
type: string
title: the subscription address that owns the project
description:
type: string
title: the description of the project for the users convinient
enabled:
type: boolean
title: enabled flag
Expand Down Expand Up @@ -56111,9 +56102,6 @@ definitions:
subscription:
type: string
title: the subscription address that owns the project
description:
type: string
title: the description of the project for the users convinient
enabled:
type: boolean
title: enabled flag
Expand Down Expand Up @@ -56208,9 +56196,6 @@ definitions:
subscription:
type: string
title: the subscription address that owns the project
description:
type: string
title: the description of the project for the users convinient
enabled:
type: boolean
title: enabled flag
Expand Down
6 changes: 6 additions & 0 deletions x/plans/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ func (m Migrator) Migrate4to5(ctx sdk.Context) error {
}
return nil
}

// Migrate5to6 implements store migration from v5 to v6:
// -- trigger fixation migration, deleteat and live variables
func (m Migrator) Migrate5to6(ctx sdk.Context) error {
return m.keeper.plansFS.MigrateVersionFrom(ctx, 3)
}
6 changes: 5 additions & 1 deletion x/plans/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 4, migrator.Migrate4to5); err != nil {
panic(fmt.Errorf("%s: failed to register migration to v5: %w", types.ModuleName, err))
}
// register v5 -> v6 migration
if err := cfg.RegisterMigration(types.ModuleName, 5, migrator.Migrate5to6); err != nil {
panic(fmt.Errorf("%s: failed to register migration to v5: %w", types.ModuleName, err))
}
}

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

// ConsensusVersion implements ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 5 }
func (AppModule) ConsensusVersion() uint64 { return 6 }

// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down
13 changes: 13 additions & 0 deletions x/projects/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,16 @@ func (m Migrator) Migrate4to5(ctx sdk.Context) error {

return nil
}

// Migrate3to4 implements store migration from v5 to v6:
// -- trigger fixation migration, deleteat and live variables
func (m Migrator) Migrate5to6(ctx sdk.Context) error {
err := m.keeper.developerKeysFS.MigrateVersionFrom(ctx, 3)
if err != nil {
return err
}

err = m.keeper.projectsFS.MigrateVersionFrom(ctx, 3)

return err
}
6 changes: 5 additions & 1 deletion x/projects/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 4, migrator.Migrate4to5); err != nil {
panic(fmt.Errorf("%s: failed to register migration to v5: %w", types.ModuleName, err))
}
// register v5 -> v6 migration
if err := cfg.RegisterMigration(types.ModuleName, 5, migrator.Migrate5to6); err != nil {
panic(fmt.Errorf("%s: failed to register migration to v5: %w", types.ModuleName, err))
}
}

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

// ConsensusVersion implements ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 5 }
func (AppModule) ConsensusVersion() uint64 { return 6 }

// 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 9a045e9

Please sign in to comment.