Skip to content

Commit

Permalink
[TRIVIAL] Fixed driver OpenAPI /reveal request definition (#3164)
Browse files Browse the repository at this point in the history
# 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 <[email protected]>
Co-authored-by: ilya <[email protected]>
  • Loading branch information
3 people authored Dec 16, 2024
1 parent ab3ec97 commit 6fe5635
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 33 deletions.
24 changes: 18 additions & 6 deletions crates/driver/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -130,7 +130,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Solution"
$ref: "#/components/schemas/SettleRequest"
responses:
"200":
description: Execution accepted.
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions crates/driver/src/infra/api/routes/reveal/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
serde_with::serde_as,
};

impl Revealed {
impl RevealResponse {
pub fn new(reveal: competition::Revealed) -> Self {
Self {
calldata: Calldata {
Expand All @@ -18,7 +18,7 @@ impl Revealed {
#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Revealed {
pub struct RevealResponse {
calldata: Calldata,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/driver/src/infra/api/routes/reveal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub(in crate::infra::api) fn reveal(router: axum::Router<State>) -> axum::Router

async fn route(
state: axum::extract::State<State>,
req: axum::Json<dto::Solution>,
) -> Result<axum::Json<dto::Revealed>, (hyper::StatusCode, axum::Json<Error>)> {
req: axum::Json<dto::RevealRequest>,
) -> Result<axum::Json<dto::RevealResponse>, (hyper::StatusCode, axum::Json<Error>)> {
let handle_request = async {
observe::revealing();
let result = state
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/infra/api/routes/settle/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod solution;
mod settle_request;

pub use solution::Solution;
pub use settle_request::SettleRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/api/routes/settle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(in crate::infra::api) fn settle(router: axum::Router<State>) -> axum::Router

async fn route(
state: axum::extract::State<State>,
req: axum::Json<dto::Solution>,
req: axum::Json<dto::SettleRequest>,
) -> Result<(), (hyper::StatusCode, axum::Json<Error>)> {
let auction_id = req.auction_id;
let solver = state.solver().name().to_string();
Expand Down
8 changes: 4 additions & 4 deletions crates/driver/src/infra/api/routes/solve/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
std::collections::HashSet,
};

impl Auction {
impl SolveRequest {
pub async fn into_domain(
self,
eth: &Ethereum,
Expand Down Expand Up @@ -198,7 +198,7 @@ impl From<auction::Error> 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<Token>,
Expand All @@ -208,7 +208,7 @@ pub struct Auction {
surplus_capturing_jit_order_owners: Vec<eth::H160>,
}

impl Auction {
impl SolveRequest {
pub fn id(&self) -> i64 {
self.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
std::collections::HashMap,
};

impl Solved {
impl SolveResponse {
pub fn new(solved: Option<competition::Solved>, solver: &Solver) -> Self {
let solutions = solved
.into_iter()
Expand All @@ -22,7 +22,7 @@ impl Solved {
#[serde_as]
#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Solved {
pub struct SolveResponse {
solutions: Vec<Solution>,
}

Expand Down
13 changes: 8 additions & 5 deletions crates/driver/src/infra/api/routes/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub(in crate::infra::api) fn solve(router: axum::Router<State>) -> axum::Router<

async fn route(
state: axum::extract::State<State>,
auction: axum::Json<dto::Auction>,
) -> Result<axum::Json<dto::Solved>, (hyper::StatusCode, axum::Json<Error>)> {
let auction_id = auction.id();
req: axum::Json<dto::SolveRequest>,
) -> Result<axum::Json<dto::SolveResponse>, (hyper::StatusCode, axum::Json<Error>)> {
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
Expand All @@ -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
Expand Down

0 comments on commit 6fe5635

Please sign in to comment.