Skip to content

Commit

Permalink
adding upgrade v1.0,7
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Oct 14, 2023
1 parent 543b50f commit c1bc9f7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,13 @@ func New(
},
)

app.UpgradeKeeper.SetUpgradeHandler(
"v1.0.7",
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
9 changes: 9 additions & 0 deletions x/rarimocore/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v3 "github.com/rarimo/rarimo-core/x/rarimocore/migrations/v3"
v4 "github.com/rarimo/rarimo-core/x/rarimocore/migrations/v4"
)

type Migrator struct {
Expand All @@ -22,3 +23,11 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error {

return nil
}

func (m Migrator) Migrate3to4(ctx sdk.Context) error {
if err := v4.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc); err != nil {
return err
}

return nil
}
33 changes: 33 additions & 0 deletions x/rarimocore/migrations/v4/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package v4

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/rarimo/rarimo-core/x/rarimocore/types"
)

func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error {
ctx.Logger().Info(fmt.Sprintf("Performing v0.0.7 %s module migrations", types.ModuleName))

params := types.Params{}
b := ctx.KVStore(storeKey).Get(types.KeyPrefix(types.ParamsKey))
cdc.MustUnmarshal(b, &params)

// Fixing the issue with unexpected slashing 1 of 2 active partis due to
// saving all violations without expiration.
for _, party := range params.Parties {
party.ViolationsCount = 0
party.ReportedSessions = []string{}
party.Status = types.PartyStatus_Active
party.FreezeEndBlock = 0
}

params.IsUpdateRequired = false

b = cdc.MustMarshal(&params)
ctx.KVStore(storeKey).Set(types.KeyPrefix(types.ParamsKey), b)
return nil
}
6 changes: 5 additions & 1 deletion x/rarimocore/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
if err := cfg.RegisterMigration(types.ModuleName, 2, am.migrator.Migrate2to3); err != nil {
panic(err)
}

if err := cfg.RegisterMigration(types.ModuleName, 3, am.migrator.Migrate3to4); err != nil {
panic(err)
}
}

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

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

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

0 comments on commit c1bc9f7

Please sign in to comment.