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

feat: Add AvailableMedians method #1657

Merged
merged 10 commits into from
Dec 15, 2022
Merged

Conversation

rbajollari
Copy link
Contributor

Description


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2022

Codecov Report

Merging #1657 (01ff5e4) into main (d104b4e) will decrease coverage by 0.08%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1657      +/-   ##
==========================================
- Coverage   55.32%   55.24%   -0.09%     
==========================================
  Files          73       73              
  Lines        7515     7527      +12     
==========================================
  Hits         4158     4158              
- Misses       3035     3043       +8     
- Partials      322      326       +4     
Impacted Files Coverage Δ
x/oracle/keeper/historic_price.go 66.45% <33.33%> (-5.58%) ⬇️

@rbajollari rbajollari marked this pull request as ready for review December 14, 2022 00:59
@rbajollari rbajollari requested a review from a team as a code owner December 14, 2022 00:59
@rbajollari rbajollari marked this pull request as draft December 14, 2022 01:08
@rbajollari rbajollari marked this pull request as ready for review December 14, 2022 01:16
x/oracle/keeper/historic_price.go Outdated Show resolved Hide resolved
Copy link
Member

@toteki toteki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

On performance, is it much of a problem to be calling AvailableMedians and then (usually) MedianOfMedians right after?

@rbajollari
Copy link
Contributor Author

Nice.

On performance, is it much of a problem to be calling AvailableMedians and then (usually) MedianOfMedians right after?

They're both going to call HistoricMedians() which iterates through medians in the store. The other option instead of having this method is to add an extra parameter to MedianOfHistoricMedians() like minMedians which would enforce a minimum amount of medians for it to return something by checking the length of the medians returned by HistoricMedians(). This would be one less call to HistoricMedians() than first calling AvailableMedians() and then MedianOfHistoricMedians(). What do you think about this approach @toteki?

@toteki
Copy link
Member

toteki commented Dec 14, 2022

I think that enforcement would create an error return, which would be indistinguishable from other more serious errors (invalid denom, etc) with inspecting the error.

What about keeping the AvailableMedians method but also adding a return to the other functions, for example MedianOfMedians(ctx,denom,numStamps) (sdk.Dec, uint32, error) where the uint32 is the number of stamps actually read?

Would reduce the load from 2 -> 1 HistoricMedians and allow leverage to determine whether a lower than expected number of stamps constitutes an error or just a case.

@rbajollari
Copy link
Contributor Author

I think that enforcement would create an error return, which would be indistinguishable from other more serious errors (invalid denom, etc) with inspecting the error.

What about keeping the AvailableMedians method but also adding a return to the other functions, for example MedianOfMedians(ctx,denom,numStamps) (sdk.Dec, uint32, error) where the uint32 is the number of stamps actually read?

Would reduce the load from 2 -> 1 HistoricMedians and allow leverage to determine whether a lower than expected number of stamps constitutes an error or just a case.

Made that update to MedianOfMedians and the other methods as well i.e. AverageOfMedians, MaxOfMedians, and MinOfMedians👍

Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should strictly avoid unnecessary operations in blockchain, which will consume extra gas. Here you only need to count elements, you don't even need to deserialize them, nor load them.

x/oracle/keeper/historic_price.go Outdated Show resolved Hide resolved
Copy link
Member

@toteki toteki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to treatment of zero case requested

x/oracle/keeper/historic_price.go Show resolved Hide resolved
Copy link
Member

@toteki toteki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, everything's been addressed

Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rbajollari rbajollari merged commit 415444f into main Dec 15, 2022
@rbajollari rbajollari deleted the ryan/available-medians-method branch December 15, 2022 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants