Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: x/oracle end_blocker panic #2185

Merged
merged 6 commits into from
Aug 5, 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
8 changes: 8 additions & 0 deletions x/oracle/keeper/historic_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ func (k Keeper) CalcAndSetHistoricMedian(
denom string,
) error {
historicPrices := k.historicPrices(ctx, denom, k.MaximumPriceStamps(ctx))
if len(historicPrices) == 0 {
k.Logger(ctx).Error(
"this should never happen",
"denom", denom,
)
return nil
}

median, err := decmath.Median(historicPrices)
if err != nil {
return errors.Wrap(err, "denom: "+denom)
Expand Down
3 changes: 3 additions & 0 deletions x/oracle/keeper/historic_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (s *IntegrationTestSuite) TestSetHistoracle#() {
// prefix to test unique prefix safety when iterating for
// similar prefixes
displayDenomVariation := displayDenom + "test"
nonExistingDenom := "nonexistingdenom"

// add multiple historic prices to store
exchangeRates := []string{"1.0", "1.2", "1.1", "1.4", "1.1", "1.15", "1.2", "1.3", "1.2"}
Expand All @@ -27,6 +28,8 @@ func (s *IntegrationTestSuite) TestSetHistoracle#() {
s.Require().NoError(err)
err = app.OracleKeeper.CalcAndSetHistoricMedian(ctx, displayDenomVariation)
s.Require().NoError(err)
err = app.OracleKeeper.CalcAndSetHistoricMedian(ctx, nonExistingDenom)
s.Require().NoError(err)
}

// update blockheight
Expand Down