From 6fe5635e25215a7e5797fdede5363bca15131732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= <47604705+mstrug@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:00:23 +0100 Subject: [PATCH] [TRIVIAL] Fixed driver OpenAPI /reveal request definition (#3164) # Description OpenAPI driver `/reveal` request has 3 fields: `solutionId`, `submissionDeadlineLatestBlock`, `auctionId` which is inconsistent with the source code, where `/reveal` request has only 2 fields: `solutionId` and `auctionId`: [source](https://github.com/cowprotocol/services/blob/main/crates/driver/src/infra/api/routes/reveal/dto/solution.rs). # Changes `/settle` and `/reveal` endpoints have same API definition: `Solution`, so I've created new API component: `SolutionWithDeadline` and assigned it to `/settle` endpoint. From `Solution` I've removed `submissionDeadlineLatestBlock` field which now aligns with `/reveal` endpoint source code. Renamed driver settle dto module `solution.rs` to `solution_with_deadline.rs` and name of the struct `Solution` to `SolutionWithDeadline`. --------- Co-authored-by: Martin Magnus Co-authored-by: ilya --- crates/driver/openapi.yml | 24 ++++++++++++++----- .../src/infra/api/routes/reveal/dto/mod.rs | 6 ++--- .../dto/{solution.rs => reveal_request.rs} | 2 +- .../dto/{revealed.rs => reveal_response.rs} | 4 ++-- .../driver/src/infra/api/routes/reveal/mod.rs | 6 ++--- .../src/infra/api/routes/settle/dto/mod.rs | 4 ++-- .../dto/{solution.rs => settle_request.rs} | 2 +- .../driver/src/infra/api/routes/settle/mod.rs | 2 +- .../src/infra/api/routes/solve/dto/mod.rs | 8 +++---- .../dto/{auction.rs => solve_request.rs} | 6 ++--- .../dto/{solved.rs => solve_response.rs} | 4 ++-- .../driver/src/infra/api/routes/solve/mod.rs | 13 ++++++---- 12 files changed, 48 insertions(+), 33 deletions(-) rename crates/driver/src/infra/api/routes/reveal/dto/{solution.rs => reveal_request.rs} (94%) rename crates/driver/src/infra/api/routes/reveal/dto/{revealed.rs => reveal_response.rs} (93%) rename crates/driver/src/infra/api/routes/settle/dto/{solution.rs => settle_request.rs} (95%) rename crates/driver/src/infra/api/routes/solve/dto/{auction.rs => solve_request.rs} (99%) rename crates/driver/src/infra/api/routes/solve/dto/{solved.rs => solve_response.rs} (98%) diff --git a/crates/driver/openapi.yml b/crates/driver/openapi.yml index 9b4a6bd812..a8d43d199f 100644 --- a/crates/driver/openapi.yml +++ b/crates/driver/openapi.yml @@ -103,14 +103,14 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/Solution" + $ref: "#/components/schemas/RevealRequest" responses: "200": description: Execution accepted. content: application/json: schema: - $ref: "#/components/schemas/RevealedResponse" + $ref: "#/components/schemas/RevealResponse" "400": $ref: "#/components/responses/BadRequest" "500": @@ -130,7 +130,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/Solution" + $ref: "#/components/schemas/SettleRequest" responses: "200": description: Execution accepted. @@ -525,8 +525,8 @@ components: $ref: "#/components/schemas/BigUint" gas: type: integer - Solution: - description: Request to the settle and reveal endpoint. + SettleRequest: + description: Request to the `/settle` endpoint. type: object properties: solutionId: @@ -541,7 +541,19 @@ components: description: Auction ID in which the specified solution ID is competing. type: integer example: 123 - RevealedResponse: + RevealRequest: + description: Request to the `/reveal` endpoint. + type: object + properties: + solutionId: + description: Id of the solution that should be executed. + type: integer + example: 123 + auctionId: + description: Auction ID in which the specified solution ID is competing. + type: integer + example: 123 + RevealResponse: description: Response of the reveal endpoint. type: object properties: diff --git a/crates/driver/src/infra/api/routes/reveal/dto/mod.rs b/crates/driver/src/infra/api/routes/reveal/dto/mod.rs index 164d4534c4..75671089e4 100644 --- a/crates/driver/src/infra/api/routes/reveal/dto/mod.rs +++ b/crates/driver/src/infra/api/routes/reveal/dto/mod.rs @@ -1,4 +1,4 @@ -mod revealed; -mod solution; +mod reveal_request; +mod reveal_response; -pub use {revealed::Revealed, solution::Solution}; +pub use {reveal_request::RevealRequest, reveal_response::RevealResponse}; diff --git a/crates/driver/src/infra/api/routes/reveal/dto/solution.rs b/crates/driver/src/infra/api/routes/reveal/dto/reveal_request.rs similarity index 94% rename from crates/driver/src/infra/api/routes/reveal/dto/solution.rs rename to crates/driver/src/infra/api/routes/reveal/dto/reveal_request.rs index 0c8d55fa49..f298b55700 100644 --- a/crates/driver/src/infra/api/routes/reveal/dto/solution.rs +++ b/crates/driver/src/infra/api/routes/reveal/dto/reveal_request.rs @@ -3,7 +3,7 @@ use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_wit #[serde_as] #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct Solution { +pub struct RevealRequest { /// Unique ID of the solution (per driver competition), to reveal. #[serde(deserialize_with = "deserialize_solution_id")] pub solution_id: u64, diff --git a/crates/driver/src/infra/api/routes/reveal/dto/revealed.rs b/crates/driver/src/infra/api/routes/reveal/dto/reveal_response.rs similarity index 93% rename from crates/driver/src/infra/api/routes/reveal/dto/revealed.rs rename to crates/driver/src/infra/api/routes/reveal/dto/reveal_response.rs index 1f256320b4..0f1d495042 100644 --- a/crates/driver/src/infra/api/routes/reveal/dto/revealed.rs +++ b/crates/driver/src/infra/api/routes/reveal/dto/reveal_response.rs @@ -4,7 +4,7 @@ use { serde_with::serde_as, }; -impl Revealed { +impl RevealResponse { pub fn new(reveal: competition::Revealed) -> Self { Self { calldata: Calldata { @@ -18,7 +18,7 @@ impl Revealed { #[serde_as] #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] -pub struct Revealed { +pub struct RevealResponse { calldata: Calldata, } diff --git a/crates/driver/src/infra/api/routes/reveal/mod.rs b/crates/driver/src/infra/api/routes/reveal/mod.rs index 750636cdaf..b96ce290f8 100644 --- a/crates/driver/src/infra/api/routes/reveal/mod.rs +++ b/crates/driver/src/infra/api/routes/reveal/mod.rs @@ -14,8 +14,8 @@ pub(in crate::infra::api) fn reveal(router: axum::Router) -> axum::Router async fn route( state: axum::extract::State, - req: axum::Json, -) -> Result, (hyper::StatusCode, axum::Json)> { + req: axum::Json, +) -> Result, (hyper::StatusCode, axum::Json)> { let handle_request = async { observe::revealing(); let result = state @@ -24,7 +24,7 @@ async fn route( .await; observe::revealed(state.solver().name(), &result); let result = result?; - Ok(axum::Json(dto::Revealed::new(result))) + Ok(axum::Json(dto::RevealResponse::new(result))) }; handle_request diff --git a/crates/driver/src/infra/api/routes/settle/dto/mod.rs b/crates/driver/src/infra/api/routes/settle/dto/mod.rs index 563b0e3cb7..0986792238 100644 --- a/crates/driver/src/infra/api/routes/settle/dto/mod.rs +++ b/crates/driver/src/infra/api/routes/settle/dto/mod.rs @@ -1,3 +1,3 @@ -mod solution; +mod settle_request; -pub use solution::Solution; +pub use settle_request::SettleRequest; diff --git a/crates/driver/src/infra/api/routes/settle/dto/solution.rs b/crates/driver/src/infra/api/routes/settle/dto/settle_request.rs similarity index 95% rename from crates/driver/src/infra/api/routes/settle/dto/solution.rs rename to crates/driver/src/infra/api/routes/settle/dto/settle_request.rs index 6c62cd0cdd..478d0766f2 100644 --- a/crates/driver/src/infra/api/routes/settle/dto/solution.rs +++ b/crates/driver/src/infra/api/routes/settle/dto/settle_request.rs @@ -3,7 +3,7 @@ use {super::super::super::deserialize_solution_id, serde::Deserialize, serde_wit #[serde_as] #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct Solution { +pub struct SettleRequest { /// Unique ID of the solution (per driver competition), to settle. #[serde(deserialize_with = "deserialize_solution_id")] pub solution_id: u64, diff --git a/crates/driver/src/infra/api/routes/settle/mod.rs b/crates/driver/src/infra/api/routes/settle/mod.rs index 6a169ce3b1..f6d073e1c7 100644 --- a/crates/driver/src/infra/api/routes/settle/mod.rs +++ b/crates/driver/src/infra/api/routes/settle/mod.rs @@ -17,7 +17,7 @@ pub(in crate::infra::api) fn settle(router: axum::Router) -> axum::Router async fn route( state: axum::extract::State, - req: axum::Json, + req: axum::Json, ) -> Result<(), (hyper::StatusCode, axum::Json)> { let auction_id = req.auction_id; let solver = state.solver().name().to_string(); diff --git a/crates/driver/src/infra/api/routes/solve/dto/mod.rs b/crates/driver/src/infra/api/routes/solve/dto/mod.rs index b7d9b72236..1fb6e69db5 100644 --- a/crates/driver/src/infra/api/routes/solve/dto/mod.rs +++ b/crates/driver/src/infra/api/routes/solve/dto/mod.rs @@ -1,7 +1,7 @@ -mod auction; -mod solved; +mod solve_request; +mod solve_response; pub use { - auction::{Auction, Error as AuctionError}, - solved::Solved, + solve_request::{Error as AuctionError, SolveRequest}, + solve_response::SolveResponse, }; diff --git a/crates/driver/src/infra/api/routes/solve/dto/auction.rs b/crates/driver/src/infra/api/routes/solve/dto/solve_request.rs similarity index 99% rename from crates/driver/src/infra/api/routes/solve/dto/auction.rs rename to crates/driver/src/infra/api/routes/solve/dto/solve_request.rs index 38138face1..b773387715 100644 --- a/crates/driver/src/infra/api/routes/solve/dto/auction.rs +++ b/crates/driver/src/infra/api/routes/solve/dto/solve_request.rs @@ -13,7 +13,7 @@ use { std::collections::HashSet, }; -impl Auction { +impl SolveRequest { pub async fn into_domain( self, eth: &Ethereum, @@ -198,7 +198,7 @@ impl From for Error { #[serde_as] #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct Auction { +pub struct SolveRequest { #[serde_as(as = "serde_with::DisplayFromStr")] id: i64, tokens: Vec, @@ -208,7 +208,7 @@ pub struct Auction { surplus_capturing_jit_order_owners: Vec, } -impl Auction { +impl SolveRequest { pub fn id(&self) -> i64 { self.id } diff --git a/crates/driver/src/infra/api/routes/solve/dto/solved.rs b/crates/driver/src/infra/api/routes/solve/dto/solve_response.rs similarity index 98% rename from crates/driver/src/infra/api/routes/solve/dto/solved.rs rename to crates/driver/src/infra/api/routes/solve/dto/solve_response.rs index 6b91523be0..892810f5f1 100644 --- a/crates/driver/src/infra/api/routes/solve/dto/solved.rs +++ b/crates/driver/src/infra/api/routes/solve/dto/solve_response.rs @@ -9,7 +9,7 @@ use { std::collections::HashMap, }; -impl Solved { +impl SolveResponse { pub fn new(solved: Option, solver: &Solver) -> Self { let solutions = solved .into_iter() @@ -22,7 +22,7 @@ impl Solved { #[serde_as] #[derive(Debug, Default, Serialize)] #[serde(rename_all = "camelCase")] -pub struct Solved { +pub struct SolveResponse { solutions: Vec, } diff --git a/crates/driver/src/infra/api/routes/solve/mod.rs b/crates/driver/src/infra/api/routes/solve/mod.rs index eccafb8ead..be9de73abe 100644 --- a/crates/driver/src/infra/api/routes/solve/mod.rs +++ b/crates/driver/src/infra/api/routes/solve/mod.rs @@ -17,13 +17,13 @@ pub(in crate::infra::api) fn solve(router: axum::Router) -> axum::Router< async fn route( state: axum::extract::State, - auction: axum::Json, -) -> Result, (hyper::StatusCode, axum::Json)> { - let auction_id = auction.id(); + req: axum::Json, +) -> Result, (hyper::StatusCode, axum::Json)> { + let auction_id = req.id(); let handle_request = async { observe::auction(auction_id); let start = Instant::now(); - let auction = auction + let auction = req .0 .into_domain(state.eth(), state.tokens(), state.timeouts()) .await @@ -38,7 +38,10 @@ async fn route( .await; let result = competition.solve(&auction).await; observe::solved(state.solver().name(), &result); - Ok(axum::Json(dto::Solved::new(result?, &competition.solver))) + Ok(axum::Json(dto::SolveResponse::new( + result?, + &competition.solver, + ))) }; handle_request