Skip to content

Commit

Permalink
fix(oracle): avg params storage. (#2260)
Browse files Browse the repository at this point in the history
* fix(oracle): v6.1 upgrade with setting missing oracle avg price params

* oracle: use avg params from the store

* set correct AvgParams prefix key

* fix

* review

* changelog
  • Loading branch information
robert-zaremba authored Sep 22, 2023
1 parent 2ee13b9 commit e1cb452
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Bug Fixes

- [2260](https://github.com/umee-network/umee/pull/2260) fix(oracle): avg params storage.

## [v6.0.2](https://github.com/umee-network/umee/releases/tag/v6.0.2) - 2023-09-20

### BugFix
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
app.registerUpgrade5_1(upgradeInfo)
app.registerUpgrade("v5.2", upgradeInfo) // v5.2 migration is not compatible with v6, so leaving default here.
app.registerUpgrade6(upgradeInfo)
app.registerUpgrade6_1("v6.1", upgradeInfo)
}

func (app *UmeeApp) registerUpgrade6_1(planName string, _ upgradetypes.Plan) {
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("-----------------------------\n-----------------------------")
err := app.OracleKeeper.SetHistoricAvgCounterParams(ctx, oracletypes.DefaultAvgCounterParams())
if err != nil {
return fromVM, err
}

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
},
)
}

func (app *UmeeApp) registerUpgrade6(upgradeInfo upgradetypes.Plan) {
Expand Down
13 changes: 5 additions & 8 deletions x/oracle/keeper/historic_avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,11 @@ func (k AvgKeeper) getCounter(denom string, idx byte) (types.AvgCounter, error)
// SetHistoricAvgCounterParams sets avg period and avg shift time duration
func (k Keeper) SetHistoricAvgCounterParams(ctx sdk.Context, acp types.AvgCounterParams) error {
kvs := ctx.KVStore(k.storeKey)
return store.SetValue(kvs, types.KeyHistoricAvgCounterParams, &acp, "historic avg counter params")
return store.SetValue(kvs, types.KeyAvgCounterParams, &acp, "historic avg counter params")
}

// GetHistoricAvgCounterParams gets the avg period and avg shift time duration from store
func (k Keeper) GetHistoricAvgCounterParams(_ sdk.Context) types.AvgCounterParams {
return types.DefaultAvgCounterParams()
// TODO: investigate why we don't have record!
// kvs := ctx.KVStore(k.storeKey)
// return *store.GetValue[*types.AvgCounterParams](kvs, types.KeyHistoricAvgCounterParams,
// "historic avg counter params")
func (k Keeper) GetHistoricAvgCounterParams(ctx sdk.Context) types.AvgCounterParams {
kvs := ctx.KVStore(k.storeKey)
return *store.GetValue[*types.AvgCounterParams](kvs, types.KeyAvgCounterParams,
"historic avg counter params")
}
6 changes: 0 additions & 6 deletions x/oracle/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ func (m Migrator) HistoracleParams3x4(ctx sdk.Context) error {
return nil
}

// SetAvgPeriodAndShift updates the avg shift and period params
func (m Migrator) SetAvgPeriodAndShift(ctx sdk.Context) error {
p := types.DefaultAvgCounterParams()
return m.keeper.SetHistoricAvgCounterParams(ctx, p)
}

// MigrateBNB fixes the BNB base denom for the 4.1 upgrade without using leverage hooks
func (m Migrator) MigrateBNB(ctx sdk.Context) {
badDenom := "ibc/77BCD42E49E5B7E0FC6B269FEBF0185B15044F13F6F38CA285DF0AF883459F40"
Expand Down
22 changes: 12 additions & 10 deletions x/oracle/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ const (

// KVStore key prefixes
var (
KeyPrefixExchangeRate = []byte{0x01} // prefix for each key to a rate
KeyPrefixFeederDelegation = []byte{0x02} // prefix for each key to a feeder delegation
KeyPrefixMissCounter = []byte{0x03} // prefix for each key to a miss counter
KeyPrefixAggregateExchangeRatePrevote = []byte{0x04} // prefix for each key to a aggregate prevote
KeyPrefixAggregateExchangeRateVote = []byte{0x05} // prefix for each key to a aggregate vote
KeyPrefixMedian = []byte{0x06} // prefix for each key to a price median
KeyPrefixMedianDeviation = []byte{0x07} // prefix for each key to a price median standard deviation
KeyPrefixHistoricPrice = []byte{0x08} // prefix for each key to a historic price
KeyPrefixAvgCounter = []byte{0x09} // prefix for each key to a historic avg price counter
KeyLatestAvgCounter = []byte{0x10} // key where we store the latest avg price counter
KeyPrefixExchangeRate = []byte{1} // prefix for each key to a rate
KeyPrefixFeederDelegation = []byte{2} // prefix for each key to a feeder delegation
KeyPrefixMissCounter = []byte{3} // prefix for each key to a miss counter
KeyPrefixAggregateExchangeRatePrevote = []byte{4} // prefix for each key to a aggregate prevote
KeyPrefixAggregateExchangeRateVote = []byte{5} // prefix for each key to a aggregate vote
KeyPrefixMedian = []byte{6} // prefix for each key to a price median
KeyPrefixMedianDeviation = []byte{7} // prefix for each key to a price median standard deviation
KeyPrefixHistoricPrice = []byte{8} // prefix for each key to a historic price
KeyPrefixAvgCounter = []byte{9} // prefix for each key to a historic avg price counter
KeyAvgCounterParams = []byte{10}

KeyLatestAvgCounter = []byte{16} // it was set as 0x10 and breaking the order
)

// KeyExchangeRate - stored by *denom*
Expand Down
1 change: 0 additions & 1 deletion x/oracle/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
KeyMedianStampPeriod = []byte("MedianStampPeriod")
KeyMaximumPriceStamps = []byte("MaximumPriceStamps")
KeyMaximumMedianStamps = []byte("MedianStampAmount")
KeyHistoricAvgCounterParams = []byte("HistoricAvgCounterParams")
)

var _ paramstypes.ParamSet = &Params{}
Expand Down

0 comments on commit e1cb452

Please sign in to comment.