-
Notifications
You must be signed in to change notification settings - Fork 82
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
base: main
Are you sure you want to change the base?
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
I was thinking about using only one table with interactions and store |
database/sql/V075__add_call_data_to_quotes_and_order_quotes.sql
Outdated
Show resolved
Hide resolved
crates/database/src/quotes.rs
Outdated
SELECT q.*, i.index, i.target, i.value, i.call_data FROM quotes q | ||
JOIN quote_interactions i ON quote_id = id | ||
WHERE id = $1 |
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.
Is it possible to aggregate the interactions directly in the quote row using SQL?
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.
Yes, it can be done using Postgres aggregate function with custom sqlx::FromRow trait implementation, I've developed working solution which after some cleanups I will commit.
database/README.md
Outdated
Solver responding to quote request provides a list of interactions which need to be executed to fulfill the quote. When order is created | ||
these interactions are copied from quote. These interactions are stored persistently and can be used to audit auction winning order. |
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.
This should be treated like user facing documentation and should therefore use proper grammar.
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.
Updated.
database/sql/V075__add_call_data_to_quotes_and_order_quotes.sql
Outdated
Show resolved
Hide resolved
); | ||
|
||
-- Get a specific quote's interactions. | ||
CREATE INDEX quote_id_interactions ON quote_interactions USING HASH (quote_id); |
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.
Was there a particular reason to not use the default index type (BTree) here?
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 decided to use hash because we don't need to query for ranges and hash map has little better performance on average (O(1) vs O(N log N)). Also we don't need to have unique index here.
impl TryFrom<database::quotes::QuoteWithInteractions> for QuoteData { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(input: database::quotes::QuoteWithInteractions) -> Result<QuoteData> { |
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.
Either this:
fn try_from(input: database::quotes::QuoteWithInteractions) -> Result<QuoteData> { | |
fn try_from((quote, interaction): database::quotes::QuoteWithInteractions) -> Result<QuoteData> { |
or use a regular QuoteWithInteractions struct with named arguments.
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.
QuoteWithInteractions
has been refactored to contain same fields as Quote
struct + interactions vector.
Due to a recent change in the API we'd need to store a bunch more data for a quote. Specifically we'd also have to store pre-interactions and JIT orders returned in a quote. Since we don't really need to introspect the quote data in the backend I'm considering whether it makes more sense to just add a single JSON column to the |
So we will need to have one column of type json, with predefined schema. The only thing which can be not so optimal is updating data in that column. If we would need to add some data then we need to read json from the column and write updated json back. But if this is not going to be a frequent action, then there should be no issue with that. |
I don't see a need to ever update the columns. The only thing that could happen is that in the future we want to store a different JSON format but in that case I'd say we should just leave the old values untouched. |
Description
Added storing of interactions received for
/quote
response sent by the solver, into new tables:quote_interactions
andorder_quote_interactions
. Storing information if quote was validated inquotes
andorder_quotes
tables.Quote interactions are used for verification/auditing orders.
Changes
Added new column
verified
toquotes
andorder_quotes
table.Added new table:
quote_interactions
which stores solver returned interactions for particular quote. Data in this table is transient and is removed together with expired quote remove.Added new table:
order_quote_interactions
which stores quote interactions permanently for particular order uid.Added database migration script and updated readme file.
How to test
Existing tests, also added dedicated tests for this new functionality..