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

Create solve competition api #188

Merged
merged 5 commits into from
May 4, 2022
Merged

Create solve competition api #188

merged 5 commits into from
May 4, 2022

Conversation

vkgnosis
Copy link
Contributor

@vkgnosis vkgnosis commented May 3, 2022

Part of #127 .

This is waiting on #185 to know the exact interface.

Next PR will make use of the post endpoint in the driver.

Test Plan

new unit tests

@vkgnosis vkgnosis requested a review from a team as a code owner May 3, 2022 11:46

pub fn post(
handler: Arc<SolverCompetition>,
expected_auth: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding auth code - we can just disallow POST solver_competition at the ingress level. We already connect to the orderbook using a cluster-local URL (so doesn't go through the ingress) and makes it so we don't need to manage secrets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Doing it only at the ingress level has the downside that an accidental misconfiguration could expose it. And we need to deal with another kubernetes configuration layer that I'm not familiar with. On the other hand it does make the code simpler and we don't want to keep this code for a long time anyway.

Copy link
Contributor

@nlordell nlordell May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would prefer it at an ingress level (I tend to prefer having generic access control configured at an ingress level as Nginx does a really good job with this). Also this avoids having to add another command line argument and plumbing it through to the API all the while making running the orderbook and solver locally for testing much easier.

an accidental misconfiguration could expose it.

To me this isn't a super strong argument since the damage that can be done isn't that big (show incorrect information in the UI while waiting for the order to trade or lie to external solvers who will have incorrect data for some batches and will likely notice something is up).

That being said, code is already there, simple enough, and will hopefully go away in the near future, so I am fine with including it in the PR.

// These types are going to be updated once the openapi documentation gets
// merged. Consider them a placeholder.

pub type SolverCompetitionResponse = HashMap<String, SolverSettlement>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a Vec<(String, SolverSettlement)> if we want to allow multiple settlements from the same solver (which, AFAIU, we currently do right - because of settlement merging?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I wrote above there, this is a placeholder until we merge the Openapi PR. Then I will make sure the types are right.

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - only comment is that we should use a Vec<SolverSettlement> instead of a map so that:

  • We can order by objective value 😄 (if you get the JSON its just a nicety that makes immediately seeing the winner and where you rank among the other settlements quicker).
  • Allows for multiple settlements per solver. We technically have this with the merged settlements - although just uploading the "best" of the merged settlements also makes a lot of sense to me.


#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
pub struct SolverSettlement {
objective_value: f64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use a Vec instead of a HashMap we should include solver_name: String here.

crates/orderbook/src/api/post_solver_competition.rs Outdated Show resolved Hide resolved
@vkgnosis
Copy link
Contributor Author

vkgnosis commented May 4, 2022

Removed the authorization code. Planning on merging this and testing the ingress config on staging.

@@ -34,13 +35,13 @@ num = "0.4"
primitive-types = { version = "0.10", features = ["fp-conversion"] }
prometheus = "0.13"
prometheus-metric-storage = { git = "https://github.com/cowprotocol/prometheus-metric-storage" , tag = "v0.4.0" }
rand = "0.8"
Copy link
Contributor

@nlordell nlordell May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is no longer needed.

Suggested change
rand = "0.8"

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving assuming that the type will be made to match the spec in a follow up PR (in order to verify the ingress configuration that will be needed).

@codecov-commenter
Copy link

codecov-commenter commented May 4, 2022

Codecov Report

Merging #188 (335331d) into main (89dbdd4) will increase coverage by 0.08%.
The diff coverage is 86.72%.

❗ Current head 335331d differs from pull request most recent head ea73d52. Consider uploading reports for the commit ea73d52 to get more accurate results

@@            Coverage Diff             @@
##             main     #188      +/-   ##
==========================================
+ Coverage   64.58%   64.66%   +0.08%     
==========================================
  Files         186      190       +4     
  Lines       38635    38741     +106     
==========================================
+ Hits        24952    25053     +101     
- Misses      13683    13688       +5     

@vkgnosis vkgnosis enabled auto-merge (squash) May 4, 2022 11:37
@vkgnosis vkgnosis merged commit dc0a571 into main May 4, 2022
@vkgnosis vkgnosis deleted the competition-route-impl branch May 4, 2022 11:40
@github-actions github-actions bot locked and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants