From ee4a8ab0529cf98d15030409d25e59a76e4f8b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= <47604705+mstrug@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:12:47 +0100 Subject: [PATCH 1/2] Remove `crates` vscode extension dependency from devcontainer (#3132) # Description Devcontainer json definition file contains vscode extension dependency: `crates` which is deprecated. As this extension is only an utility for checking `Cargo.toml` dependency creates versions and is not needed for devcontainer to work on our codebase, we decided to drop that extension from our devcontainer json definition file. Anyone can still use `crates` or similar extension (like `dependi`) in devcontainer by installing it locally in vscode. Reference discussion: [link](https://cowservices.slack.com/archives/C0375NV72SC/p1731961303020439) # Changes Updated `devcontainer.json` file. ## How to test Open vscode from `services` folder and on popup window click option "Open in devcontainer" (docker daemon is required to operate). Wait for containers setup and validation by rust analyzer. --- .devcontainer/devcontainer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c4d49550c8..00c2bca3c9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -41,8 +41,7 @@ ] }, "extensions": [ - "rust-lang.rust-analyzer", - "serayuzgur.crates" + "rust-lang.rust-analyzer" ] } }, From 98596753c7f8298731b490328a6dbc4650c907f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= <47604705+mstrug@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:00:36 +0100 Subject: [PATCH 2/2] Added optional auction_id field to /settle and /reveal requests (#3131) # Description Update to PR #3113 which changes `auction_id` field to be optional. --- .../autopilot/src/infra/solvers/dto/reveal.rs | 7 ++++--- .../autopilot/src/infra/solvers/dto/settle.rs | 7 ++++--- crates/autopilot/src/run_loop.rs | 2 +- crates/autopilot/src/shadow.rs | 2 +- crates/driver/src/domain/competition/mod.rs | 18 ++++++++++++++---- .../infra/api/routes/reveal/dto/solution.rs | 6 +++--- .../infra/api/routes/settle/dto/solution.rs | 6 +++--- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/crates/autopilot/src/infra/solvers/dto/reveal.rs b/crates/autopilot/src/infra/solvers/dto/reveal.rs index 1cd0848919..e8ac28f02a 100644 --- a/crates/autopilot/src/infra/solvers/dto/reveal.rs +++ b/crates/autopilot/src/infra/solvers/dto/reveal.rs @@ -1,9 +1,10 @@ use { serde::{Deserialize, Serialize}, - serde_with::serde_as, + serde_with::{serde_as, skip_serializing_none}, }; #[serde_as] +#[skip_serializing_none] #[derive(Clone, Debug, Default, Serialize)] #[serde(rename_all = "camelCase")] pub struct Request { @@ -11,8 +12,8 @@ pub struct Request { #[serde_as(as = "serde_with::DisplayFromStr")] pub solution_id: u64, /// Auction ID in which the specified solution ID is competing. - #[serde_as(as = "serde_with::DisplayFromStr")] - pub auction_id: i64, + #[serde_as(as = "Option")] + pub auction_id: Option, } #[serde_as] diff --git a/crates/autopilot/src/infra/solvers/dto/settle.rs b/crates/autopilot/src/infra/solvers/dto/settle.rs index 3ffba83df3..0269e9425d 100644 --- a/crates/autopilot/src/infra/solvers/dto/settle.rs +++ b/crates/autopilot/src/infra/solvers/dto/settle.rs @@ -1,10 +1,11 @@ use { primitive_types::H256, serde::{Deserialize, Serialize}, - serde_with::serde_as, + serde_with::{serde_as, skip_serializing_none}, }; #[serde_as] +#[skip_serializing_none] #[derive(Clone, Debug, Default, Serialize)] #[serde(rename_all = "camelCase")] pub struct Request { @@ -14,8 +15,8 @@ pub struct Request { /// The last block number in which the solution TX can be included pub submission_deadline_latest_block: u64, /// Auction ID in which the specified solution ID is competing. - #[serde_as(as = "serde_with::DisplayFromStr")] - pub auction_id: i64, + #[serde_as(as = "Option")] + pub auction_id: Option, } #[serde_as] diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index d1eac70afe..6228d81fcd 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -807,7 +807,7 @@ impl RunLoop { let request = settle::Request { solution_id, submission_deadline_latest_block, - auction_id, + auction_id: None, // Requires 2-stage release for API-break change }; driver .settle(&request, self.config.max_settlement_transaction_wait) diff --git a/crates/autopilot/src/shadow.rs b/crates/autopilot/src/shadow.rs index 44db5bd203..beddd86acc 100644 --- a/crates/autopilot/src/shadow.rs +++ b/crates/autopilot/src/shadow.rs @@ -276,7 +276,7 @@ impl RunLoop { let revealed = driver .reveal(&reveal::Request { solution_id, - auction_id: request.id, + auction_id: None, // Requires 2-stage release for API-break change }) .await .map_err(Error::Reveal)?; diff --git a/crates/driver/src/domain/competition/mod.rs b/crates/driver/src/domain/competition/mod.rs index 5fb3cab346..dd3aa06073 100644 --- a/crates/driver/src/domain/competition/mod.rs +++ b/crates/driver/src/domain/competition/mod.rs @@ -267,13 +267,20 @@ impl Competition { Ok(score) } - pub async fn reveal(&self, solution_id: u64, auction_id: i64) -> Result { + pub async fn reveal( + &self, + solution_id: u64, + auction_id: Option, + ) -> Result { let settlement = self .settlements .lock() .unwrap() .iter() - .find(|s| s.solution().get() == solution_id && s.auction_id.0 == auction_id) + .find(|s| { + s.solution().get() == solution_id + && auction_id.is_none_or(|id| s.auction_id.0 == id) + }) .cloned() .ok_or(Error::SolutionNotAvailable)?; Ok(Revealed { @@ -292,7 +299,7 @@ impl Competition { /// [`Competition::solve`] to generate the solution. pub async fn settle( &self, - auction_id: i64, + auction_id: Option, solution_id: u64, submission_deadline: u64, ) -> Result { @@ -300,7 +307,10 @@ impl Competition { let mut lock = self.settlements.lock().unwrap(); let index = lock .iter() - .position(|s| s.solution().get() == solution_id && s.auction_id.0 == auction_id) + .position(|s| { + s.solution().get() == solution_id + && auction_id.is_none_or(|id| s.auction_id.0 == id) + }) .ok_or(Error::SolutionNotAvailable)?; // remove settlement to ensure we can't settle it twice by accident lock.swap_remove_front(index) diff --git a/crates/driver/src/infra/api/routes/reveal/dto/solution.rs b/crates/driver/src/infra/api/routes/reveal/dto/solution.rs index 60e8f564bc..77a80e28b1 100644 --- a/crates/driver/src/infra/api/routes/reveal/dto/solution.rs +++ b/crates/driver/src/infra/api/routes/reveal/dto/solution.rs @@ -2,12 +2,12 @@ use {serde::Deserialize, serde_with::serde_as}; #[serde_as] #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase", deny_unknown_fields)] +#[serde(rename_all = "camelCase")] pub struct Solution { /// Unique ID of the solution (per driver competition), to reveal. #[serde_as(as = "serde_with::DisplayFromStr")] pub solution_id: u64, /// Auction ID in which the specified solution ID is competing. - #[serde_as(as = "serde_with::DisplayFromStr")] - pub auction_id: i64, + #[serde_as(as = "Option")] + pub auction_id: Option, } diff --git a/crates/driver/src/infra/api/routes/settle/dto/solution.rs b/crates/driver/src/infra/api/routes/settle/dto/solution.rs index ab2a52e2ec..cbe0441ac3 100644 --- a/crates/driver/src/infra/api/routes/settle/dto/solution.rs +++ b/crates/driver/src/infra/api/routes/settle/dto/solution.rs @@ -2,7 +2,7 @@ use {serde::Deserialize, serde_with::serde_as}; #[serde_as] #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase", deny_unknown_fields)] +#[serde(rename_all = "camelCase")] pub struct Solution { /// Unique ID of the solution (per driver competition), to settle. #[serde_as(as = "serde_with::DisplayFromStr")] @@ -10,6 +10,6 @@ pub struct Solution { /// The last block number in which the solution TX can be included pub submission_deadline_latest_block: u64, /// Auction ID in which this solution is competing. - #[serde_as(as = "serde_with::DisplayFromStr")] - pub auction_id: i64, + #[serde_as(as = "Option")] + pub auction_id: Option, }