-
Notifications
You must be signed in to change notification settings - Fork 93
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
Added QuoteMetadata
to /orders/uid
request
#3222
base: main
Are you sure you want to change the base?
Conversation
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
QuoteMetadata
to /quotes/uid
requestQuoteMetadata
to /orders/uid
request
Why don't we want to use QuoteMetadadaV1 in the API schema instead of raw json? How is it expected to use this data? |
Intended use of the quote metadata in /orders/uid response is for debugging/analysis of the quotes from the auction winning solution by the solvers teams. |
crates/model/src/order.rs
Outdated
/// If the order was crated with a quote, then this field contains the | ||
/// quote's metadata. | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub quote_metadata: Option<serde_json::Value>, |
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.
Given that it's also helpful to expose the actual quoted amounts I think the format of this would better be sth like:
quote: {
// .. fields stored in `order_quotes` table
}
That would expose all the necessary data at once.
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Updated PR description. |
order | ||
.map(|order_with_quote| { | ||
|
||
let order = match orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0)).await? { |
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.
We could have an early return to None
in order to avoid one indexation level.
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'm not sure where we can do the early return, because for the None
match we are checking jit 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.
orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0))
.await?
.or_else(|| async {
database::jit_orders::get_by_id(&mut ex, &ByteArray(uid.0))
.await?
.map(full_order_into_model_order)
})
.transpose()
Or
if let Some(order) = orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0)).await? {
return Ok(Some(order))
}
database::jit_orders::get_by_id(&mut ex, &ByteArray(uid.0))
.await?
.map(full_order_into_model_order)
.transpose()
}
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.
Thank you @squadgazzz ! exactly I meant that.
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.
Ok, I get what you meant. Refactored.
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.
Not much changed tbh :)
The main benefit of an early return is reducing indentation, making the code easier to read.
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.
So improved the code readability by moving the Quote match to separate function, but in my opinion I don't see here an issue with the indentation.
@@ -1280,10 +1248,16 @@ mod tests { | |||
}, | |||
..Default::default() | |||
}; | |||
db.insert_order(&order, Some(quote)).await.unwrap(); | |||
db.insert_order(&order, Some(quote.clone())).await.unwrap(); |
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.
the db.insert_order()
signature is now quite weird to me. The order struct now contains quote metadata but we still pass an optional quote into it. This immediately begs the question what is supposed to happen when order.metadata.quote
is different from the passed in quote?
Can this API be updated to not have this conflict anymore?
I suspect the underlying problem is probably that we are using the Order
and OrderMetadata
struct in too many places so it currently wears a lot of different hats which don't quite work in all places. 🤔
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.
The main issue is that shared::order_quoting::Quote
returned by validate_and_construct_order()
can be converted to model::order::OrderQuote
(order.metadata.quote
field) but cannot be converted back (for storing in db) because of lack of some fields and I'm not sure if it is sensible to add all of the missing fields (mainly quote id
which will be irrelevant after clearing quotes table, but also most of the QuoteData
fields).
Also order.metadata.quote
is created from the quote
so it always has the same values.
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.
Also order.metadata.quote is created from the quote so it always has the same values.
That doesn't really help to reduce currently created confusion where we operate with 2 quotes related to the same order but in different representations.
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.
Still thinking about how this part can be improved:
services/crates/orderbook/src/database/orders.rs
Lines 240 to 242 in 81c3029
if let Some(quote) = quote { | |
insert_quote(&order.metadata.uid, "e, &mut ex).await?; | |
} |
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.
The main issue is that shared::order_quoting::Quote returned by validate_and_construct_order() can be converted to model::order::OrderQuote (order.metadata.quote field) but cannot be converted back
I'd say the main issue is that we pass a ton of data into the DB call that is actually not needed. I believe if we only pass the necessary data (signed order data + a few additional data) we'd not have the issue of passing 2 possibly conflicting Quote
structs into the same call.
Co-authored-by: ilya <[email protected]>
Description
Exposing
Quote
data in the orderbook API on/orders/uid
endpoint.Changes
This is a follow up of PR #3124 which added storing in the database of some quote information (like interactions, jit orders and pre interactions) for auctions analysis in the order context. Current PR exposes these information (plus the whole quote data) through API, so any interested party can easily access this data.
OrderQuote
quote
to theOrderMetadata
OrderWithQuote
type as the quote is already insideOrder
struct (throughmetadata
field)How to test
Updated two tests which validates if proper quote metadata is returned. Current e2e tests.
Tested locally on playground that order quote is returned through API.