Skip to content

Commit

Permalink
migration fixes (#893)
Browse files Browse the repository at this point in the history
* migration fixes

* reducing upgrade height
  • Loading branch information
avkr003 authored Oct 29, 2024
1 parent 3a4d28c commit 19e2455
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# helper functions
extract_txhash() { awk -F 'txhash: ' '/txhash:/{print $2; exit}'; }
extract_proposal_id() { awk -F 'key: proposal_id|value: ' '/key: proposal_id/ { getline; gsub(/"/, "", $2); print $2; exit }'; }
extract_and_calc_upgrade_height() { awk -F'"latest_block_height":"' '{ split($2,a,"\""); print a[1]+4500; exit }'; }
extract_and_calc_upgrade_height() { awk -F'"latest_block_height":"' '{ split($2,a,"\""); print a[1]+500; exit }'; }
extract_checksum() { awk "/elysd-${{ github.ref_name }}-linux-amd64.tar.gz/ {print \$1; exit}"; }
# environment variables
Expand Down
13 changes: 13 additions & 0 deletions x/accountedpool/migrations/new_migrator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package migrations

import (
"github.com/elys-network/elys/x/accountedpool/keeper"
)

type Migrator struct {
keeper keeper.Keeper
}

func NewMigrator(keeper keeper.Keeper) Migrator {
return Migrator{keeper: keeper}
}
13 changes: 13 additions & 0 deletions x/accountedpool/migrations/v2_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package migrations

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

func (m Migrator) V2Migration(ctx sdk.Context) error {
allAccountedPool := m.keeper.GetAllAccountedPool(ctx)
for _, accountedPool := range allAccountedPool {
m.keeper.RemoveAccountedPool(ctx, accountedPool.PoolId)
}
return nil
}
8 changes: 7 additions & 1 deletion x/accountedpool/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/elys-network/elys/x/accountedpool/client/cli"
"github.com/elys-network/elys/x/accountedpool/keeper"
"github.com/elys-network/elys/x/accountedpool/migrations"
"github.com/elys-network/elys/x/accountedpool/types"
)

Expand Down Expand Up @@ -115,6 +116,11 @@ func NewAppModule(
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 1, m.V2Migration)
if err != nil {
panic(err)
}
}

// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted)
Expand All @@ -138,7 +144,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 1 }
func (AppModule) ConsensusVersion() uint64 { return 2 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
Expand Down
26 changes: 26 additions & 0 deletions x/leveragelp/migrations/v16_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package migrations

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

func (m Migrator) V16Migration(ctx sdk.Context) error {
allPools := m.keeper.GetAllPools(ctx)

for _, pool := range allPools {
hooks := m.keeper.GetHooks()

if hooks != nil {
ammPool, err := m.keeper.GetAmmPool(ctx, pool.AmmPoolId)
if err != nil {
return err
}
err = hooks.AfterEnablingPool(ctx, ammPool)
if err != nil {
return err
}
}
}

return nil
}
4 changes: 2 additions & 2 deletions x/leveragelp/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 14, m.V15Migration)
err := cfg.RegisterMigration(types.ModuleName, 15, m.V16Migration)
if err != nil {
panic(err)
}
Expand All @@ -144,7 +144,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 15 }
func (AppModule) ConsensusVersion() uint64 { return 16 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
Expand Down

0 comments on commit 19e2455

Please sign in to comment.