-
Notifications
You must be signed in to change notification settings - Fork 501
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
services/horizon: Gracefully handle non-canonical prices in GET /order_book #2400
Merged
2opremio
merged 2 commits into
release-horizon-v1.1.0
from
2010-fix-order-book-price-levels
Mar 20, 2020
Merged
services/horizon: Gracefully handle non-canonical prices in GET /order_book #2400
2opremio
merged 2 commits into
release-horizon-v1.1.0
from
2010-fix-order-book-price-levels
Mar 20, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2opremio
force-pushed
the
2010-fix-order-book-price-levels
branch
from
March 19, 2020 22:07
3ac08ea
to
a8da652
Compare
I am missing tests, but the approach is ready to review. |
@2opremio this looks great! I can approve once you add tests |
2opremio
commented
Mar 19, 2020
2opremio
commented
Mar 19, 2020
Due to the non-canonical rational representation of offer prices, they were not being compared properly in a bunch of places, leading to an incorrect result of `GET order_book` (the `limit` parameter wasn't respected and levels not being coalesced properly) when equal prices with different representation were involved. This happened in: 1. `graph.findOffers()`, which treated equal prices with different representation as different price levels. 2. `offersToPriceLevels()`, which computed multiple levels for equal prices with different representation. This change fixes the problems above by adding and using comparison operations which take non-canonical representations into account. In addition, the prices output in order_book are now normalized (which is a requirement in order to properly coalesce prices with identical value but different representation). Alternatively, we could use Go's `math/big.Rat` to ingesting offers (since `Rat`s are always normalized) but it may be useful to keep the original values from the ledger as is for debugging purposes.
2opremio
force-pushed
the
2010-fix-order-book-price-levels
branch
from
March 20, 2020 18:04
8960199
to
7533207
Compare
@tamirms this is ready to review, I have added the tests. |
@2opremio can you add update graph_test.go to make sure |
@tamirms Done! |
tamirms
approved these changes
Mar 20, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
needed with deprecations, added features, breaking changes, and DB schema changes.
semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
Fixes #2010
Due to the non-canonical rational representation of offer prices, they were not being compared properly in a bunch of places, leading to an incorrect result of
GET order_book
(thelimit
parameter wasn't respected and levels were not being coalesced properly) when equal prices with different representation were involved .
This happened in:
graph.findOffers()
, which treated equal prices with differentrepresentation as different price levels.
offersToPriceLevels()
, which computed multiple levels forequal prices with different representation.
This change fixes the problems above by adding and using comparison operations which take non-canonical representations into account.
In addition, the prices output in order_book are now normalized (which is a requirement in order to properly coalesce prices with identical value but different representation).
Alternatively, we could use Go's
math/big.Rat
for storing ingested offer prices (sinceRat
s are always normalized) but it may be useful to keep the original values from the ledger as is for debugging purposes.