Skip to content

Commit

Permalink
Merge branch 'main' into start-indexing-from-settlement-contract-star…
Browse files Browse the repository at this point in the history
…t-block
  • Loading branch information
m-lord-renkse authored Nov 20, 2024
2 parents deeb403 + 9859675 commit eb3ebe2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
]
},
"extensions": [
"rust-lang.rust-analyzer",
"serayuzgur.crates"
"rust-lang.rust-analyzer"
]
}
},
Expand Down
7 changes: 4 additions & 3 deletions crates/autopilot/src/infra/solvers/dto/reveal.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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 {
/// 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<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
}

#[serde_as]
Expand Down
7 changes: 4 additions & 3 deletions crates/autopilot/src/infra/solvers/dto/settle.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
}

#[serde_as]
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
18 changes: 14 additions & 4 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,20 @@ impl Competition {
Ok(score)
}

pub async fn reveal(&self, solution_id: u64, auction_id: i64) -> Result<Revealed, Error> {
pub async fn reveal(
&self,
solution_id: u64,
auction_id: Option<i64>,
) -> Result<Revealed, Error> {
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 {
Expand All @@ -292,15 +299,18 @@ impl Competition {
/// [`Competition::solve`] to generate the solution.
pub async fn settle(
&self,
auction_id: i64,
auction_id: Option<i64>,
solution_id: u64,
submission_deadline: u64,
) -> Result<Settled, Error> {
let settlement = {
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)
Expand Down
6 changes: 3 additions & 3 deletions crates/driver/src/infra/api/routes/reveal/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
}
6 changes: 3 additions & 3 deletions crates/driver/src/infra/api/routes/settle/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ 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")]
pub solution_id: u64,
/// 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<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
}

0 comments on commit eb3ebe2

Please sign in to comment.