-
Notifications
You must be signed in to change notification settings - Fork 83
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
Storing call_data in quotes and order_quotes tables #3124
Conversation
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 we now want to store the data in the db the PR also needs a db migration file (database/sql directory) and an update in the db Readme for that.
Reminder: Please update the DB Readme. Caused by: |
database/sql/V075__add_call_data_to_quotes_and_order_quotes.sql
Outdated
Show resolved
Hide resolved
database/sql/V075__add_call_data_to_quotes_and_order_quotes.sql
Outdated
Show resolved
Hide resolved
@mstrug is this ready for review? |
Yes |
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.
Just a few remaining nits.
database/sql_revert/V075__revert_add_metadata_to_quotes_and_order_quotes.sql
Outdated
Show resolved
Hide resolved
-- This migration script is reversible. | ||
|
||
-- Step 1: Add two new columns to the quotes table | ||
ALTER TABLE quotes |
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.
for historic quotes verified columns value could be wrong
That's true although I'd prefer a cleaner DB model over perfect historic data that will never be read. Also if anybody really cares about the accuracy of that data we know when the migration got applied and can detect historic values with the {}
metadata value.
To support deserialization of |
metadata: quote.data.metadata.try_into().map_err( | ||
|e: serde_json::Error| { | ||
AddOrderError::MetadataSerializationFailed(e.into()) | ||
}, | ||
)?, |
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.
nit:
metadata: quote.data.metadata.try_into().map_err( | |
|e: serde_json::Error| { | |
AddOrderError::MetadataSerializationFailed(e.into()) | |
}, | |
)?, | |
metadata: quote.data.metadata.try_into().map_err(AddOrderError::MetadataSerializationFailed)?, |
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.
To apply that change, I also had to updated definition of AddOrderError::MetadataSerializationFailed
to take serde_json::Error
as its unnamed field.
#[serde(untagged)] | ||
enum QuoteMetadataDeserializationHelper { | ||
Data(QuoteMetadata), | ||
Empty {}, |
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.
If we were to add this to QuoteMetadata
wouldn't work directly without the need of another enum? 🤔
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.
As for QuoteMetadata
I use #[serde(tag = "version")]
to achieve this flattening and converting QuoteMetadata
variants to version
json tag, which implies requiring that version
tag exists in the input json, which is not possible for empty json object.
Generally, to get automatic conversion from empty json object {}
to Empty {}
variant, we need to use #[serde(untagged)]
which cannot be used on QuoteMetadata
where we use #[serde(tag = "version")]
.
Alternative approach that I have also considered is a custom implementation of the serde deserialize trait, but this becomes more complicated and requires more code (additional implementation of visitor trait) comparing to helper type approach.
@@ -44,6 +51,12 @@ pub enum TradeKind { | |||
Regular(Trade), | |||
} | |||
|
|||
impl Default for TradeKind { |
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.
nit: cannot this be directly derived?
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.
Unfortunately it cannot be derived directly, as Rust currently is not supporting #[default]
attribute on non-unit enum variants.
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.
Nice job!!
Description
Added two new non-null columns:
metadata
(json) andverified
(boolean) into tablesquotes
andorder_quotes
.Existing rows in database will be updated with
{}
andfalse
values.metadata
column is dedicated to store any additional data for the quote in json format. Currently it is used to store interactions received for/quote
response from the solvers, but it is prepared to store other data in future through versionedQuoteMetadata
struct as required.Database module only checks json validity, upper layers (orderbook, autopilot) uses
QuoteMetadata
struct for storing specific data in the database.Metadata can be used for verification/auditing of quotes/orders.
Added database migration scripts (update and revert) and updated database readme file.
How to test
Existing tests, also added dedicated e2e tests and unit tests for this new functionality .