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

Added QuoteMetadata to /orders/uid request #3222

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

mstrug
Copy link
Contributor

@mstrug mstrug commented Jan 8, 2025

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.

  • Added new type OrderQuote
  • Added new field quote to the OrderMetadata
  • Removed OrderWithQuote type as the quote is already inside Order struct (through metadata 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.

Copy link

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.

@github-actions github-actions bot added the stale label Jan 16, 2025
@mstrug mstrug removed the stale label Jan 16, 2025
@mstrug mstrug changed the title Added QuoteMetadata to /quotes/uid request Added QuoteMetadata to /orders/uid request Jan 17, 2025
@mstrug mstrug marked this pull request as ready for review January 23, 2025 01:52
@mstrug mstrug requested a review from a team as a code owner January 23, 2025 01:53
@squadgazzz
Copy link
Contributor

squadgazzz commented Jan 23, 2025

Why don't we want to use QuoteMetadadaV1 in the API schema instead of raw json? How is it expected to use this data?

@mstrug
Copy link
Contributor Author

mstrug commented Jan 23, 2025

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.
Because of that the quote metadata in OrderMetadata struct from the data model is not used internally, except that one case of providing that data to the users through API. So I think that the data model doesn't need to know the exact type of the quote metadata.
QuoteMetadataV1 is used only during order quoting to gather metadata for particular quote and store it in database also as raw json value.

/// 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>,
Copy link
Contributor

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.

Copy link

github-actions bot commented Feb 1, 2025

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.

@github-actions github-actions bot added the stale label Feb 1, 2025
@mstrug mstrug removed the stale label Feb 4, 2025
@mstrug mstrug marked this pull request as draft February 4, 2025 14:47
Copy link

coderabbitai bot commented Feb 7, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mstrug
Copy link
Contributor Author

mstrug commented Feb 14, 2025

Updated PR description.

@mstrug mstrug marked this pull request as ready for review February 14, 2025 23:51
order
.map(|order_with_quote| {

let order = match orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0)).await? {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@squadgazzz squadgazzz Feb 18, 2025

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()
}

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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. 🤔

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 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.

Copy link
Contributor

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.

Copy link
Contributor

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:

if let Some(quote) = quote {
insert_quote(&order.metadata.uid, &quote, &mut ex).await?;
}

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants