Skip to content

Commit

Permalink
fix: epochs infos missing start time (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond authored Apr 1, 2024
1 parent 96d8a99 commit acea93f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
24 changes: 0 additions & 24 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package app

import (
"fmt"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
m "github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -22,28 +20,6 @@ func setUpgradeHandler(app *ElysApp) {
func(ctx sdk.Context, plan upgradetypes.Plan, vm m.VersionMap) (m.VersionMap, error) {
app.Logger().Info("Running upgrade handler for " + version.Version)

if version.Version == "v0.29.29" {
app.Logger().Info("Decommission deprecated pool #1")
pool, found := app.AmmKeeper.GetPool(ctx, 1)
if found {
// withdraw all liquidity from the pool
allCommitments := app.CommitmentKeeper.GetAllCommitments(ctx)
for _, commitments := range allCommitments {
addr, err := sdk.AccAddressFromBech32(commitments.Creator)
if err != nil {
continue
}
for _, committedToken := range commitments.CommittedTokens {
if committedToken.Denom == fmt.Sprintf("amm/pool/%d", pool.PoolId) {
app.AmmKeeper.ExitPool(ctx, addr, pool.PoolId, committedToken.Amount, sdk.NewCoins(), "")
}
}
}
// remove the pool
app.AmmKeeper.RemovePool(ctx, pool.PoolId)
}
}

return app.mm.RunMigrations(ctx, app.configurator, vm)
},
)
Expand Down
67 changes: 67 additions & 0 deletions x/epochs/migrations/v3_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package migrations

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/epochs/types"
)

func (m Migrator) V3Migration(ctx sdk.Context) error {
// twelve hours
m.keeper.SetEpochInfo(ctx, types.EpochInfo{
Identifier: "twelvehours",
Duration: time.Hour * 12,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
EpochCountingStarted: false,
CurrentEpochStartTime: time.Now(),
StartTime: time.Now(),
})

// six hours
m.keeper.SetEpochInfo(ctx, types.EpochInfo{
Identifier: "sixhours",
Duration: time.Hour * 6,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
EpochCountingStarted: false,
CurrentEpochStartTime: time.Now(),
StartTime: time.Now(),
})

// four hours
m.keeper.SetEpochInfo(ctx, types.EpochInfo{
Identifier: "fourhours",
Duration: time.Hour * 4,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
EpochCountingStarted: false,
CurrentEpochStartTime: time.Now(),
StartTime: time.Now(),
})

// two hours
m.keeper.SetEpochInfo(ctx, types.EpochInfo{
Identifier: "twohours",
Duration: time.Hour * 2,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
EpochCountingStarted: false,
CurrentEpochStartTime: time.Now(),
StartTime: time.Now(),
})

// half hour
m.keeper.SetEpochInfo(ctx, types.EpochInfo{
Identifier: "halfhour",
Duration: time.Minute * 30,
CurrentEpoch: 0,
CurrentEpochStartHeight: 0,
EpochCountingStarted: false,
CurrentEpochStartTime: time.Now(),
StartTime: time.Now(),
})

return nil
}
4 changes: 2 additions & 2 deletions x/epochs/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (am AppModule) NewHandler() sdk.Handler {
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 1, m.V2Migration)
err := cfg.RegisterMigration(types.ModuleName, 2, m.V3Migration)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -183,4 +183,4 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
}

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

0 comments on commit acea93f

Please sign in to comment.