Skip to content

Commit

Permalink
CNS-45: added migrator for Spec (added blockLatestUpdate)
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Dec 11, 2022
1 parent 65b350a commit d294ddf
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 15 deletions.
14 changes: 14 additions & 0 deletions app/upgrades/v0.2.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package v020

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/lavanet/lava/app/upgrades"
)

const UpgradeName = "v0.2.0"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName, // upgrade name defined few lines above
CreateUpgradeHandler: CreateUpgradeHandler, // create CreateUpgradeHandler in upgrades.go below
StoreUpgrades: store.StoreUpgrades{}, // StoreUpgrades has 3 fields: Added/Renamed/Deleted any module that fits these description should be added in the way below
}
47 changes: 47 additions & 0 deletions app/upgrades/v0.2.0/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//go:build ignore

package v020_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
keepertest "github.com/lavanet/lava/testutil/keeper"
v020 "github.com/lavanet/lava/x/spec/migrations/v0.2.0"
"github.com/stretchr/testify/suite"
)

type UpgradeTestSuite struct {
suite.Suite

ctx sdk.Context
app cosmoscmd.App
}

func (suite *UpgradeTestSuite) SetupTestApp() {
suite.app, suite.ctx = app.TestSetup()
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (suite *UpgradeTestSuite) TestBody() {
suite.SetupTestApp() // setup test app
suite.T().Log("test")
}

func (suite *UpgradeTestSuite) TestAddingBlockLastUpdated() {
_, keepers, ctx := keepertest.InitAllKeepers(suite.T())
sdkctx := sdk.UnwrapSDKContext(ctx)
suite.T().Log("TestAddingBlockLastUpdated")

migrator := v020.NewMigrator(keepers.Spec)
migrator.MigrateToV020(sdkctx)

allSpec := keepers.Spec.GetAllSpec(sdk.UnwrapSDKContext(ctx))
for _, spec := range allSpec {
suite.Require().Equal(0, spec.BlockLastUpdated)
}
}
31 changes: 31 additions & 0 deletions app/upgrades/v0.2.0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package v020

import (
"log"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/lavanet/lava/app/keepers"
"github.com/lavanet/lava/app/upgrades"
v020 "github.com/lavanet/lava/x/spec/migrations/v0.2.0"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.LavaKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
log.Println("########################")
log.Println("# STARTING UPGRADE #")
log.Println("########################")

//delete all existing conflicts
migrator := v020.NewMigrator(keepers.SpecKeeper)
migrator.MigrateToV020(ctx)

return mm.RunMigrations(ctx, configurator, vm)
}
}
16 changes: 1 addition & 15 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29513,9 +29513,6 @@ paths:
items:
type: string
format: uint64
averageBlockTime:
type: string
format: uint64
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -30311,7 +30308,7 @@ paths:
type: string
tags:
- Query
'/lavanet/lava/pairing/get_pairing/{chainID}/{client}/{blockHeight}':
'/lavanet/lava/pairing/get_pairing/{chainID}/{client}':
get:
summary: Queries a list of GetPairing items.
operationId: LavanetLavaPairingGetPairing
Expand Down Expand Up @@ -30403,11 +30400,6 @@ paths:
in: path
required: true
type: string
- name: blockHeight
in: path
required: true
type: string
format: int64
tags:
- Query
/lavanet/lava/pairing/params:
Expand Down Expand Up @@ -53081,9 +53073,6 @@ definitions:
items:
type: string
format: uint64
averageBlockTime:
type: string
format: uint64
lavanet.lava.epochstorage.FixatedParams:
type: object
properties:
Expand Down Expand Up @@ -53250,9 +53239,6 @@ definitions:
items:
type: string
format: uint64
averageBlockTime:
type: string
format: uint64
lavanet.lava.epochstorage.QueryGetFixatedParamsResponse:
type: object
properties:
Expand Down
28 changes: 28 additions & 0 deletions x/spec/migrations/v0.2.0/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v020 // migrations.go

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/x/spec/keeper"
)

type Migrator struct {
keeper keeper.Keeper
}

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

func (m Migrator) MigrateToV020(ctx sdk.Context) error {
return initBlockLastUpdated(ctx, m.keeper)
}

func initBlockLastUpdated(ctx sdk.Context, k keeper.Keeper) error {
specs := k.GetAllSpec(ctx)
for _, spec := range specs {
spec.BlockLastUpdated = uint64(0)
k.SetSpec(ctx, spec)
}

return nil
}

0 comments on commit d294ddf

Please sign in to comment.