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 4 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")
}
2 changes: 2 additions & 0 deletions x/oracle/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
// related to v6.0.1.
return nil
}

Expand Down
21 changes: 11 additions & 10 deletions x/oracle/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
KeyAvgCounterParams = []byte{11}
)

// 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