-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incremental solvable orders cache update (#2923)
# Description > Updating solvable orders (ie creating a new auction) currently takes >2s with some pretty heavy outliers ([logs](https://production-6de61f.kb.eu-central-1.aws.cloud.es.io/app/r/s/ALsEK)) > > This makes it hard to bring CoW protocol's auction rate down to one batch per block as simply creating up to date state would take >15% of the total time we have at hand. We should at least be able to half this time (if not getting it down even more) In order to relieve the situation, it was proposed to introduce incremental solvable orders cache update, which selects all the solvable orders using the old heavy query only at startup, stores the latest received order's creation timestamp in memory, and then makes much faster incremental bounded queries to the orders and additional tables that select fewer data and executes faster. # Changes Since incremental fetching retrieves orders created/cancelled after the specific timestamps, it is also required now to fetch orders that have any onchain update based on the last fetched block number. Having said that, the data needs to be fetched within a single TX, so there is no way to run all the queries in parallel. 1. If the current solvable orders cache is empty, execute the original heavy SQL query to fetch all current solvable orders and store them in memory. 2. Otherwise, fetch full orders that created or cancelled after the last stored timestamp and also find UIDs of the order that have any onchain data updated after the latest observed block number. This includes fetching data from the following tables: trades, ethflow_data, order_execution, invalidations, onchain_order_invalidations, onchain_placed_orders, presignature_events. 3. Fetch quotes for all the collected orders. 4. Add all the newly received orders to the cache. 5. Filter out all the orders that are one of: contain on-chain errors, expired, fulfilled, invalidated. 6. Calculate the latest observed order creation timestamp. 7. Continue with the regular auction creation process. As a result, we now have 3 SQL queries where each executes in ~50ms instead of a single one taking ~2s. ## How to test New DB tests. Existing e2e tests. ## Related Issues Fixes #2831
- Loading branch information
1 parent
12aa87b
commit ed09b91
Showing
11 changed files
with
607 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.