-
Notifications
You must be signed in to change notification settings - Fork 97
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
Do not count "in-market" orders for the order limit #2433 #2456
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
82a6558
Do not count "in-market" orders for the order limit #2433
m-lord-renkse f74923b
Calculate in-market based on the stored quote
m-lord-renkse 10bc0b3
Check for number of limit orders also for liquidity orders
m-lord-renkse 9a0bbd5
Merge branch 'main' into do-not-count-in-market-orders-for-limit
m-lord-renkse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a SQL query that counts limit orders. Instead of fetching all this data and counting in the rust code you could have the in-market check already in SQL to only return a single number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinquaXD how could we do that? we need to precisely operate the
f64
so we can consider thelimit
order as "out of market" 🤔 do you mean by doing the operation directly in SQL?see https://github.com/cowprotocol/services/pull/2456/files#diff-d22c8612ee861d55e838fdc5487a1c139da73b795295670acdcccea91f805011R386
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically reimplement the logic of
is_order_outside_market_price()
insidecount_limit_orders_by_owner()
. Hopefully there is a way in PSQL to convert the types appropriately for the computation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinquaXD In my opinion, doing arithmetical operations in PSQL query involving U256 and f64 is really not a good idea (unless it is plain sum, and even so), we are going to lose precision, and we are going to push CPU overhead to the database. What's more, I don't think we will save time, since database CPU is less powerful than the backend CPU, and the rust code will be definitely faster.
I understand your concern of potential long queries in case the user placed many orders, for that please, consider adding the internal class (as I proposed here #2456 (comment)), which will tackle down all the issues. We could also do the queries by pagination in case of long queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Why do you think so?
This is also the case in the rust code since
.fee()
callsU256::from_f64_lossy()
.Computations might be faster in rust but I very much doubt that returning all that data, parsing it, allocating the structs (1 Vec per BigDecimal) and doing the computation in rust will be faster than doing a computation inside the db and returning a single number.
This is not a hill I'm willing to die on (although I disagree) if you feel strongly about keeping the computation out of the DB I'd at least consider fetching the data using a stream instead of call
.fetch_all()
to limit the memory consumption when a user has lots of orders.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we would need to benchmark this in order to get a definitive answer. It's true that for accounts with a lot of orders this may become a bottleneck. In theory we could also decide the "in-marketness" of an order when it's inserted into the db (and then simply count based on a flag)?
I'd be curious how PSQL math is less accurate than rust math?