Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oracle): avg params storage. #2260

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-----------------------------")
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
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
10 changes: 4 additions & 6 deletions x/oracle/keeper/historic_avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +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 {
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.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
Loading