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

feat: Update oracle endblocker for historic # #1580

Merged
merged 20 commits into from
Nov 23, 2022

Conversation

rbajollari
Copy link
Contributor

Description

closes: #1542


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)

@rbajollari rbajollari self-assigned this Nov 11, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2022

Codecov Report

Merging #1580 (26ce029) into main (3953226) will decrease coverage by 1.04%.
The diff coverage is 22.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1580      +/-   ##
==========================================
- Coverage   55.09%   54.05%   -1.05%     
==========================================
  Files          68       71       +3     
  Lines        6835     7150     +315     
==========================================
+ Hits         3766     3865      +99     
- Misses       2787     2988     +201     
- Partials      282      297      +15     
Impacted Files Coverage Δ
x/oracle/keeper/historic_price.go 81.81% <0.00%> (-9.78%) ⬇️
x/oracle/module.go 53.24% <0.00%> (ø)
x/oracle/abci.go 47.57% <27.77%> (ø)
x/oracle/types/params.go 96.15% <100.00%> (+0.04%) ⬆️
x/oracle/genesis.go 4.23% <0.00%> (ø)

if isPeriodLastBlock(ctx, params.PrunePeriod) {
pruneBlock := uint64(ctx.BlockHeight()) - params.PrunePeriod
for _, v := range params.AcceptList {
k.DeleteHistoricPrice(ctx, v.String(), pruneBlock)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
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.

  • endblocker tests should be extended to cover new functionality
  • Median computation should be correctly benchmarked (with right amount of data, eg: 20 tokens, with full amount of prices).
  • need to validate the stamp price usage.

@rbajollari rbajollari marked this pull request as ready for review November 21, 2022 16:50
@rbajollari rbajollari requested a review from a team as a code owner November 21, 2022 16:50
@zarazan
Copy link
Contributor

zarazan commented Nov 21, 2022

Could we use the experimental flag instead of commenting out the code? And then the test can set the experimental flag.


if experimental {
// Stamp rate every stamp period if asset is set to have historic stats tracked
if isPeriodLastBlock(ctx, params.StampPeriod) && params.HistoricAcceptList.Contains(ballotDenom.Denom) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

if experimental {
// Stamp rate every stamp period if asset is set to have historic stats tracked
if isPeriodLastBlock(ctx, params.StampPeriod) && params.HistoricAcceptList.Contains(ballotDenom.Denom) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if experimental {
// Stamp rate every stamp period if asset is set to have historic stats tracked
if isPeriodLastBlock(ctx, params.StampPeriod) && params.HistoricAcceptList.Contains(ballotDenom.Denom) {
k.AddHistoricPrice(ctx, ballotDenom.Denom, exchangeRate)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// Set median price every median period if asset is set to have historic stats tracked
if isPeriodLastBlock(ctx, params.MedianPeriod) && params.HistoricAcceptList.Contains(ballotDenom.Denom) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// Set median price every median period if asset is set to have historic stats tracked
if isPeriodLastBlock(ctx, params.MedianPeriod) && params.HistoricAcceptList.Contains(ballotDenom.Denom) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

// Set median price every median period if asset is set to have historic stats tracked
if isPeriodLastBlock(ctx, params.MedianPeriod) && params.HistoricAcceptList.Contains(ballotDenom.Denom) {
k.CalcAndSetMedian(ctx, ballotDenom.Denom)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
k.SlashAndResetMissCounters(ctx)
}

// Prune historic prices every prune period
if isPeriodLastBlock(ctx, params.PrunePeriod) && experimental {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Copy link
Contributor

@zarazan zarazan left a comment

Choose a reason for hiding this comment

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

Couple comments, looks great!


k.ClearExchangeRates(ctx)

if isPeriodLastBlock(ctx, params.MedianPeriod) && experimental {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

k.ClearExchangeRates(ctx)

if isPeriodLastBlock(ctx, params.MedianPeriod) && experimental {
k.ClearMedians(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

k.ClearExchangeRates(ctx)

if isPeriodLastBlock(ctx, params.MedianPeriod) && experimental {
k.ClearMedians(ctx)
k.ClearMedianDeviations(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@rbajollari rbajollari requested a review from zarazan November 22, 2022 20:11
Copy link
Contributor

@zarazan zarazan left a comment

Choose a reason for hiding this comment

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

Love it, thanks for adding that test!

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.

The functionality looks wrong. I think we wanted to have a rolling median. Let's confirm in Slack. Blocking for the moment.

@rbajollari rbajollari merged commit f468a4c into main Nov 23, 2022
@rbajollari rbajollari deleted the ryan/historacle-endblocker branch November 23, 2022 00:36
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add price stamping to the oracle endblocker
4 participants