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: Last error time now updates during record interpolation #2923

Merged
merged 10 commits into from
Nov 4, 2022
Merged

Fix: Last error time now updates during record interpolation #2923

merged 10 commits into from
Nov 4, 2022

Conversation

migueldingli1997
Copy link
Contributor

@migueldingli1997 migueldingli1997 commented Oct 1, 2022

Closes: #2909

What is the purpose of the change

This pull request resolves the issue that interpolated records that have an error were no longer considered erroneous after interpolation. In other words, if the last error time matches the record's time, these will also match in the interpolated record.

Brief Changelog

  • Last error time is updated during record interpolation if record has an error

Testing and Verifying

This change added tests and can be verified as follows:

  • Added unit test that ensures the last error time is updated if the record's time matches the last error time

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? no
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? yes
  • How is the feature or change documented? not documented

@migueldingli1997 migueldingli1997 requested a review from a team October 1, 2022 09:45
@github-actions github-actions bot added the C:x/twap Changes to the twap module label Oct 1, 2022
@github-actions github-actions bot added the C:docs Improvements or additions to documentation label Oct 1, 2022
@migueldingli1997 migueldingli1997 changed the title Last error time now updates during record interpolation Fix: Last error time now updates during record interpolation Oct 1, 2022
@ValarDragon ValarDragon added the V:state/breaking State machine breaking PR label Oct 1, 2022
@ValarDragon
Copy link
Member

This looks good to me!

Can you add the test case you had in the github issue, which ensures the needed property at the api level?

@migueldingli1997
Copy link
Contributor Author

This looks good to me!

Can you add the test case you had in the github issue, which ensures the needed property at the api level?

Sure thing

@migueldingli1997
Copy link
Contributor Author

I have not had the time to continue working on this, however please note that that after I added some additional rough test cases, there seems to be an issue at the API level as a result of my changes.

@github-actions github-actions bot removed the C:docs Improvements or additions to documentation label Oct 14, 2022
@@ -719,7 +742,7 @@ func (s *TestSuite) TestGetArithmeticTwapToNow() {

if test.expectedError != nil {
s.Require().Error(err)
s.Require().ErrorIs(err, test.expectedError)
s.Require().Equal(test.expectedError, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ErrorIs does not work for spotPriceError so I changed it to an Equals

@migueldingli1997
Copy link
Contributor Author

migueldingli1997 commented Oct 14, 2022

Updated @ValarDragon :) Please review the PR in its entirety as I did not just add a test; I modified the fix as well.

Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

All the core logic for this LGTM, nice catch btw!

Left some minor comments for this PR, please take a look

CHANGELOG.md Outdated Show resolved Hide resolved
x/twap/logic.go Show resolved Hide resolved
if endRecord.LastErrorTime.After(startRecord.Time) || endRecord.LastErrorTime.Equal(startRecord.Time) {
if endRecord.LastErrorTime.After(startRecord.Time) ||
endRecord.LastErrorTime.Equal(startRecord.Time) ||
startRecord.LastErrorTime.Equal(startRecord.Time) {
Copy link
Member

Choose a reason for hiding this comment

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

curious, do we not need to add startRecord.LastErrorTime.Equal(startRecord.Time)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider the case where:

  • endRecord = {Time: 2, LastErrTime: 0}
  • startRecord = {Time: 1, LastErrTime: 1}

The conditions will evaluate to the following:

  • endRecord.LastErrorTime.After(startRecord.Time) - False
  • endRecord.LastErrorTime.Equal(startRecord.Time) - False
  • startRecord.LastErrorTime.Equal(startRecord.Time) - True

Without the third condition, the calculation proceeds. And we do not want it to proceed because the startRecord has an error at its time.

The case is definitely possible because the startRecord might have been interpolated before being passed to this function (e.g. from {Time: 0, LastErrTime: 0} to {Time: 1, LastErrTime: 1}) while the endRecord is untouched.

x/twap/api_test.go Show resolved Hide resolved
Co-authored-by: Matt, Park <[email protected]>
Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

This LGTM!

Apologies for delay in review, the dragonberry security bug got in the way 😅

x/twap/logic.go Outdated Show resolved Hide resolved
@ValarDragon ValarDragon merged commit b7b4db6 into osmosis-labs:main Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/twap Changes to the twap module V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible unreported error from GetArithmeticTwap
4 participants