Skip to content

Commit

Permalink
Fix score format (#2075)
Browse files Browse the repository at this point in the history
# Description
Standard way to serde U256 in our system is in a decimal format.
By default, U256 is serde in hexadecimal format.

This PR fixes that so that score is consistent with other data.
  • Loading branch information
sunce86 authored Nov 27, 2023
1 parent d583ec3 commit 1be0d01
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
10 changes: 8 additions & 2 deletions crates/driver/src/infra/solver/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ impl Solutions {
.try_collect()?,
solver.clone(),
match solution.score {
Score::Solver(score) => competition::solution::SolverScore::Solver(score),
Score::Solver { score } => {
competition::solution::SolverScore::Solver(score)
}
Score::RiskAdjusted(success_probability) => {
competition::solution::SolverScore::RiskAdjusted(success_probability)
}
Expand Down Expand Up @@ -373,9 +375,13 @@ enum SigningScheme {
Eip1271,
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
pub enum Score {
Solver(eth::U256),
Solver {
#[serde_as(as = "serialize::U256")]
score: eth::U256,
},
RiskAdjusted(f64),
}
6 changes: 4 additions & 2 deletions crates/driver/src/tests/cases/score_competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn solver_score_winner() {
let test = setup()
.pool(ab_pool())
.order(ab_order())
.solution(ab_solution().score(Score::Solver(2902421280589416499u128.into()))) // not higher than objective value
.solution(ab_solution().score(Score::Solver { score: 2902421280589416499u128.into()})) // higher than objective value
.solution(ab_solution().score(Score::RiskAdjusted(0.4)))
.done()
.await;
Expand All @@ -29,7 +29,9 @@ async fn risk_adjusted_score_winner() {
let test = setup()
.pool(ab_pool())
.order(ab_order())
.solution(ab_solution().score(Score::Solver(DEFAULT_SCORE_MIN.into())))
.solution(ab_solution().score(Score::Solver {
score: DEFAULT_SCORE_MIN.into(),
}))
.solution(ab_solution().score(Score::RiskAdjusted(0.9)))
.done()
.await;
Expand Down
9 changes: 7 additions & 2 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ use {
},
setup::blockchain::Blockchain,
},
util,
util::{self, serialize},
},
ethcontract::BlockId,
hyper::StatusCode,
itertools::Itertools,
secp256k1::SecretKey,
serde_with::serde_as,
std::{
collections::{HashMap, HashSet},
path::PathBuf,
Expand Down Expand Up @@ -54,10 +55,14 @@ pub enum Partial {
},
}

#[serde_as]
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Score {
Solver(eth::U256),
Solver {
#[serde_as(as = "serialize::U256")]
score: eth::U256,
},
RiskAdjusted(f64),
}

Expand Down
8 changes: 6 additions & 2 deletions crates/solvers/src/api/routes/solve/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Solutions {
})
.collect(),
score: match solution.score.clone() {
solution::Score::Solver(score) => Score::Solver(score),
solution::Score::Solver(score) => Score::Solver { score },
solution::Score::RiskAdjusted(score) => Score::RiskAdjusted(score.0),
},
})
Expand Down Expand Up @@ -319,9 +319,13 @@ enum SigningScheme {
}

/// A score for a solution. The score is used to rank solutions.
#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Score {
Solver(U256),
Solver {
#[serde_as(as = "serialize::U256")]
score: U256,
},
RiskAdjusted(f64),
}

0 comments on commit 1be0d01

Please sign in to comment.