From 86b2a601ec260bdf7e60353557e2ddf76a930b01 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 21 Sep 2023 17:16:17 +0200 Subject: [PATCH 1/6] fix(oracle): v6.1 upgrade with setting missing oracle avg price params --- app/upgrades.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/upgrades.go b/app/upgrades.go index 46e7dd8d45..da6163a50a 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -57,6 +57,23 @@ 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(upgradeInfo) +} + +func (app *UmeeApp) registerUpgrade6_1(upgradeInfo upgradetypes.Plan) { + planName := "v6.1" + + 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) { From ad08f60d548957932a26568b0a316119f0677794 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 21 Sep 2023 17:16:34 +0200 Subject: [PATCH 2/6] oracle: use avg params from the store --- x/oracle/keeper/historic_avg.go | 8 +++----- x/oracle/keeper/migrations.go | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/oracle/keeper/historic_avg.go b/x/oracle/keeper/historic_avg.go index 8e354e0b4a..66c67da849 100644 --- a/x/oracle/keeper/historic_avg.go +++ b/x/oracle/keeper/historic_avg.go @@ -154,9 +154,7 @@ func (k Keeper) SetHistoricAvgCounterParams(ctx sdk.Context, acp types.AvgCounte // GetHistoricAvgCounterParams gets the avg period and avg shift time duration from store func (k Keeper) GetHistoricAvgCounterParams(ctx 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") + kvs := ctx.KVStore(k.storeKey) + return *store.GetValue[*types.AvgCounterParams](kvs, types.KeyHistoricAvgCounterParams, + "historic avg counter params") } diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index 53774de819..92addf286e 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -21,6 +21,8 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { m.keeper.SetMedianStampPeriod(ctx, 1) m.keeper.SetMaximumPriceStamps(ctx, 1) m.keeper.SetMaximumMedianStamps(ctx, 1) + // NOTE: call to m.SetAvgPeriodAndShift is missing here, and caused a chain halt + // related to v6.0.1. return nil } From c5b3fc990b4f927d1cbd6529b2186ce62cba1003 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 21 Sep 2023 18:19:00 +0200 Subject: [PATCH 3/6] set correct AvgParams prefix key --- x/oracle/types/keys.go | 21 +++++++++++---------- x/oracle/types/params.go | 1 - 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x/oracle/types/keys.go b/x/oracle/types/keys.go index 53359f0f36..29f0cbd4f8 100644 --- a/x/oracle/types/keys.go +++ b/x/oracle/types/keys.go @@ -19,16 +19,17 @@ 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 + KeyLatestAvgCounter = []byte{10} // key where we store the latest avg price counter + KeyAvgCounterParams = []byte{11} ) // 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{} From 4b33082732e4e82d0a0a98b93cefb15686285f86 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 21 Sep 2023 18:27:03 +0200 Subject: [PATCH 4/6] fix --- app/upgrades.go | 6 ++---- x/oracle/keeper/historic_avg.go | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index da6163a50a..a51a37de18 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -57,12 +57,10 @@ 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(upgradeInfo) + app.registerUpgrade6_1("v6.1", upgradeInfo) } -func (app *UmeeApp) registerUpgrade6_1(upgradeInfo upgradetypes.Plan) { - planName := "v6.1" - +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-----------------------------") diff --git a/x/oracle/keeper/historic_avg.go b/x/oracle/keeper/historic_avg.go index 66c67da849..455970c97f 100644 --- a/x/oracle/keeper/historic_avg.go +++ b/x/oracle/keeper/historic_avg.go @@ -149,12 +149,12 @@ 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(ctx sdk.Context) types.AvgCounterParams { kvs := ctx.KVStore(k.storeKey) - return *store.GetValue[*types.AvgCounterParams](kvs, types.KeyHistoricAvgCounterParams, + return *store.GetValue[*types.AvgCounterParams](kvs, types.KeyAvgCounterParams, "historic avg counter params") } From 0f8188d53fa6fe26afd28f5ca873e89487b8a5cf Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 21 Sep 2023 19:18:15 +0200 Subject: [PATCH 5/6] review --- x/oracle/keeper/migrations.go | 8 -------- x/oracle/types/keys.go | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index 92addf286e..c26c90b9b0 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -21,8 +21,6 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { m.keeper.SetMedianStampPeriod(ctx, 1) m.keeper.SetMaximumPriceStamps(ctx, 1) m.keeper.SetMaximumMedianStamps(ctx, 1) - // NOTE: call to m.SetAvgPeriodAndShift is missing here, and caused a chain halt - // related to v6.0.1. return nil } @@ -37,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 29f0cbd4f8..3ef456f483 100644 --- a/x/oracle/types/keys.go +++ b/x/oracle/types/keys.go @@ -19,17 +19,18 @@ const ( // KVStore key prefixes var ( - 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 - KeyLatestAvgCounter = []byte{10} // key where we store the latest avg price counter - KeyAvgCounterParams = []byte{11} + 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* From f3cd9226be9a60583d7655fed33907dae58a93f4 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 21 Sep 2023 19:31:27 +0200 Subject: [PATCH 6/6] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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