-
Notifications
You must be signed in to change notification settings - Fork 84
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
Fix solver competition reading #3171
Conversation
FROM solver_competitions sc | ||
-- outer joins because the data might not have been indexed yet | ||
LEFT OUTER JOIN settlements s ON sc.id = s.auction_id | ||
-- exclude settlements from another environment for which observation is guaranteed to not exist | ||
LEFT OUTER JOIN settlement_observations so |
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.
LEFT OUTER JOIN
makes sure there is no change in logic whether solver competition entry is returned or not
@@ -38,10 +38,14 @@ pub async fn load_by_id( | |||
id: AuctionId, | |||
) -> Result<Option<LoadCompetition>, sqlx::Error> { | |||
const QUERY: &str = r#" | |||
SELECT sc.json, sc.id, COALESCE(ARRAY_AGG(s.tx_hash) FILTER (WHERE s.tx_hash IS NOT NULL), '{}') AS tx_hashes | |||
SELECT sc.json, sc.id, COALESCE(ARRAY_AGG(s.tx_hash) FILTER (WHERE so.block_number IS NOT NULL), '{}') AS tx_hashes |
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.
Return transaction hash only if settlement_observation
entry exists.
@@ -72,11 +80,17 @@ WITH competition AS ( | |||
SELECT sc.id | |||
FROM solver_competitions sc | |||
JOIN settlements s ON sc.id = s.auction_id | |||
JOIN settlement_observations so |
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.
JOIN
because we don't want to return solver competition entry for a transaction that was settled in different environment.
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, a fix without having to update the db at all. 🚀
Also thanks for adding a test. 👍
The only drawback of this solution is that But I think this is a trade off we can live with. |
I agree that this drawback shouldn't block this fix. |
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 only drawback of this solution is that settlement_observation table exists from 1 March of 2023, so for competitions ran before that date, this logic will not work 100% (transaction hashes will be missing).
That’s a very insightful remark.
Description
Fixes a bug where transaction hashes from different environment (prod/staging) are shown on solver competition endpoint.
Example: https://api.cow.fi/mainnet/api/v1/solver_competition/9861815
Here, transaction
0xb608f1e2a644befda65a6a87ce6b93fc8a3441d9729b8ce4b2a2db02c1247e60
is from production enviroment and valid one, while0xc85cd0ad8e3aac389836a71da9795bdd1bedce7b21da1950b48f93165c9f6be8
is from staging environment and mistakenly added to result.The reason why this happens is:
auction_id
can be saved in both environments, regardless if the competition ended up with mined settlement (which is fine).settlement::Observer
saves the relationship <auction, settlement> even for settlements from another environment (this is a decision made long time ago, before refactoring, reference code here )But, what this PR introduces is leveraging the fact that, for settlement from another environment, there is no matching entry in
settlement_observations
table, reference code here. Note how the saving is executed only if thesettlement
exists, which if false for settlements from another environment.Changes
How to test
Updated unit test.
Existing e2e tests.
Manually tested all updated functions on production database, works as expected.