diff --git a/CHANGELOG.md b/CHANGELOG.md index a2eb0c40fe..5183aabada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/upgrades.go b/app/upgrades.go index 46e7dd8d45..a51a37de18 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -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) { diff --git a/x/oracle/keeper/historic_avg.go b/x/oracle/keeper/historic_avg.go index 820da66ee5..2fd0069bfb 100644 --- a/x/oracle/keeper/historic_avg.go +++ b/x/oracle/keeper/historic_avg.go @@ -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") } diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index 53774de819..c26c90b9b0 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -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" diff --git a/x/oracle/types/keys.go b/x/oracle/types/keys.go index 53359f0f36..3ef456f483 100644 --- a/x/oracle/types/keys.go +++ b/x/oracle/types/keys.go @@ -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* diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index 69fad2c690..50ad4a49e1 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -37,7 +37,6 @@ var ( KeyMedianStampPeriod = []byte("MedianStampPeriod") KeyMaximumPriceStamps = []byte("MaximumPriceStamps") KeyMaximumMedianStamps = []byte("MedianStampAmount") - KeyHistoricAvgCounterParams = []byte("HistoricAvgCounterParams") ) var _ paramstypes.ParamSet = &Params{}