Skip to content

Commit

Permalink
feat: add oracle migration for v3.2 (#1593)
Browse files Browse the repository at this point in the history
## Description

Migration fixing tthe oracle params set.

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Nov 18, 2022
1 parent cd1fc23 commit bcd3e5a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
39 changes: 24 additions & 15 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,40 @@ func (app UmeeApp) RegisterUpgradeHandlers(experimental bool) {

app.registerV3_0Upgrade(upgradeInfo)
app.registerV3_1Upgrade(upgradeInfo)
app.registerV3_2Upgrade(upgradeInfo)
}

func onlyRunMigrations(app *UmeeApp, planName string) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", planName)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
}
}

// performs upgrade from v3.1 -> v3.2
func (app *UmeeApp) registerV3_2Upgrade(_ upgradetypes.Plan) {
const planName = "v3.2.0"
app.UpgradeKeeper.SetUpgradeHandler(planName, onlyRunMigrations(app, planName))
}

// performs upgrade from v3.0 -> v3.1
func (app *UmeeApp) registerV3_1Upgrade(_ upgradetypes.Plan) {
const UpgradeV3_1Plan = "v3.1.0"
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeV3_1Plan,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", UpgradeV3_1Plan)
return fromVM, nil
})
const planName = "v3.1.0"
app.UpgradeKeeper.SetUpgradeHandler(planName, onlyRunMigrations(app, planName))
}

// performs upgrade from v1->v3
func (app *UmeeApp) registerV3_0Upgrade(upgradeInfo upgradetypes.Plan) {
const UpgradeV3_0Plan = "v1.1-v3.0"
const planName = "v1.1-v3.0"
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeV3_0Plan,
planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Upgrade handler execution", "name", UpgradeV3_0Plan)
ctx.Logger().Info("Upgrade handler execution", "name", planName)
ctx.Logger().Info("Running setupBech32ibcKeeper")
err := upgradev3.SetupBech32ibcKeeper(&app.bech32IbcKeeper, ctx)
if err != nil {
return nil, sdkerrors.Wrapf(
err, "%q Upgrade: Unable to upgrade, bech32ibc module not initialized", UpgradeV3_0Plan)
err, "%q Upgrade: Unable to upgrade, bech32ibc module not initialized", planName)
}

ctx.Logger().Info("Running module migrations")
Expand All @@ -61,22 +70,22 @@ func (app *UmeeApp) registerV3_0Upgrade(upgradeInfo upgradetypes.Plan) {
if err != nil {
return vm, sdkerrors.Wrapf(
err, "%q Upgrade: failed to update minimum commission rate param of staking module",
UpgradeV3_0Plan)
planName)
}

ctx.Logger().Info("Upgrade handler execution finished, updating minimum commission rate of all validators",
"name", UpgradeV3_0Plan)
"name", planName)
err = upgradev3.SetMinimumCommissionRateToValidators(ctx, app.StakingKeeper, minCommissionRate)
if err != nil {
return vm, sdkerrors.Wrapf(
err, "%q Upgrade: failed to update minimum commission rate for validators",
UpgradeV3_0Plan)
planName)
}

return vm, err
})

if upgradeInfo.Name == UpgradeV3_0Plan && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
if upgradeInfo.Name == planName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
group.ModuleName,
Expand Down
26 changes: 26 additions & 0 deletions x/oracle/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package keeper

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

"github.com/umee-network/umee/v3/x/oracle/types"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper *Keeper
}

// NewMigrator creates a Migrator.
func NewMigrator(keeper *Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
m.keeper.SetStampPeriod(ctx, 1)
m.keeper.SetPrunePeriod(ctx, 1)
m.keeper.SetMedianPeriod(ctx, 1)
m.keeper.SetHistoricAcceptList(ctx, types.DenomList{})
return nil
}
6 changes: 3 additions & 3 deletions x/oracle/keeper/params.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package keeper

import (
"github.com/umee-network/umee/v3/x/oracle/types"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/umee-network/umee/v3/x/oracle/types"
)

// VotePeriod returns the number of blocks during which voting takes place.
Expand Down Expand Up @@ -58,7 +58,7 @@ func (k Keeper) IsHistoricAsset(ctx sdk.Context, denom string) bool {
return k.HistoricAcceptList(ctx).Contains(denom)
}

// SetAcceptList updates the the list of assets whose historic prices and
// SetHistoricAcceptList updates the the list of assets whose historic prices and
// medians are getting tracked.
func (k Keeper) SetHistoricAcceptList(ctx sdk.Context, historicAcceptList types.DenomList) {
k.paramSpace.Set(ctx, types.KeyHistoricAcceptList, historicAcceptList)
Expand Down
9 changes: 6 additions & 3 deletions x/oracle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func (AppModuleBasic) Name() string {
return types.ModuleName
}

func (AppModuleBasic) ConsensusVersion() uint64 {
return 1
}
func (AppModuleBasic) ConsensusVersion() uint64 { return 2 }

// RegisterInterfaces registers the x/oracle module's interface types.
func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
Expand Down Expand Up @@ -150,6 +148,11 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.keeper))

m := keeper.NewMigrator(&am.keeper)
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
panic(fmt.Sprintf("failed to migrate x/oracle from version 1 to 2: %v", err))
}
}

// RegisterInvariants registers the x/oracle module's invariants.
Expand Down

0 comments on commit bcd3e5a

Please sign in to comment.