Skip to content

Commit

Permalink
Added migration to fix entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Segfaultd committed Dec 14, 2023
1 parent 089de7f commit d50611a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
11 changes: 11 additions & 0 deletions x/millions/keeper/keeper_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,14 @@ func (k Keeper) ListDeposits(ctx sdk.Context) (deposits []types.Deposit) {
}
return
}

func (k Keeper) UnsafeSetUnpersistedDeposits(ctx sdk.Context) int {
i := 0
for _, deposit := range k.ListDeposits(ctx) {
k.setPoolDeposit(ctx, &deposit)
k.setAccountDeposit(ctx, &deposit)
i++
}

return i
}
11 changes: 11 additions & 0 deletions x/millions/keeper/keeper_withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,14 @@ func (k Keeper) ListPoolWithdrawals(ctx sdk.Context, poolID uint64) (withdrawals
}
return
}

func (k Keeper) UnsafeSetUnpersistedWithdrawals(ctx sdk.Context) int {
i := 0
for _, withdrawal := range k.ListWithdrawals(ctx) {
k.setPoolWithdrawal(ctx, withdrawal)
k.setAccountWithdrawal(ctx, withdrawal)
i++
}

return i
}
6 changes: 6 additions & 0 deletions x/millions/migrations/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migrations

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v164 "github.com/lum-network/chain/x/millions/migrations/v164"

millionskeeper "github.com/lum-network/chain/x/millions/keeper"
v150 "github.com/lum-network/chain/x/millions/migrations/v150"
Expand Down Expand Up @@ -37,3 +38,8 @@ func (m Migrator) Migrate3To4(ctx sdk.Context) error {
func (m Migrator) Migrate4To5(ctx sdk.Context) error {
return v162.MigratePendingWithdrawalsToNewEpochUnbonding(ctx, m.keeper)
}

// Migrate5To6 migrates from version 5 to 6
func (m Migrator) Migrate5To6(ctx sdk.Context) error {
return v164.SaveEntitiesOnAccountLevel(ctx, m.keeper)
}
17 changes: 17 additions & 0 deletions x/millions/migrations/v164/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v164

import (
sdk "github.com/cosmos/cosmos-sdk/types"
millionskeeper "github.com/lum-network/chain/x/millions/keeper"
)

func SaveEntitiesOnAccountLevel(ctx sdk.Context, k millionskeeper.Keeper) error {
ctx.Logger().Info("Saving entities on account level")

updatedDeposits := k.UnsafeSetUnpersistedDeposits(ctx)
updatedWithdrawals := k.UnsafeSetUnpersistedWithdrawals(ctx)

ctx.Logger().Info("Saving entities on account level: deposits", "count", updatedDeposits)
ctx.Logger().Info("Saving entities on account level: withdrawals", "count", updatedWithdrawals)
return nil
}
5 changes: 5 additions & 0 deletions x/millions/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func (a AppModule) RegisterServices(cfg module.Configurator) {
if err != nil {
panic(err)
}

err = cfg.RegisterMigration(types.ModuleName, 5, migrator.Migrate5To6)
if err != nil {
panic(err)
}
}

func (a AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down
2 changes: 1 addition & 1 deletion x/millions/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const (
ModuleName = "millions"

ModuleVersion = 5
ModuleVersion = 6

StoreKey = ModuleName

Expand Down

0 comments on commit d50611a

Please sign in to comment.