-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Refactor score calculation (#1993)
# Description No new functionality (actually fixes bug, because before this we did not check the validity of score if provided by solver as is, we did the checks only for risk adjusted scores). Moves out score calculation out of the boundary settlement. A step forward for #1973 and prerequisite for implementing task #4 from #1891 # Changes - Added objective_value calculation on boundary settlement - Added score forwarding on boundary settlement - With these two, score calculation is moved out to domain::settlement - Score calculator moved to boundary::score and used by ☝️ - These two allowed to define domain::score::Error and propagate errors properly.
- voptional-request-sharing
- vmemleak
- vcow-amm-task
- vbalancer-cow-amms
- varbitrum
- v-tokio-perf-debug
- v-colocation-test
- v-allocator-tcmalloc
- v-allocator-snmalloc
- v-allocator-jemalloc
- v2.288.0
- v2.287.1
- v2.287.0
- v2.286.0
- v2.285.2
- v2.285.1
- v2.285.0
- v2.284.0
- v2.284.0-3122
- v2.283.1
- v2.283.1-base
- v2.283.0
- v2.282.4
- v2.282.2
- v2.282.1
- v2.282.0
- v2.281.1
- v2.281.0
- v2.280.1
- v2.280.0
- v2.279.0
- v2.278.0
- v2.278.0-native-price-cache-improvement
- v2.277.3
- v2.277.2
- v2.277.1
- v2.277.0
- v2.276.1
- v2.276.0
- v2.275.4
- v2.275.3
- v2.275.2
- v2.275.1
- v2.275.0
- v2.274.1
- v2.274.0
- v2.273.1
- v2.273.0
- v2.272.1
- v2.272.0
- v2.271.0
- v2.270.1
- v2.270.0
- v2.269.1
- v2.269.0
- v2.268.1
- v2.268.0
- v2.267.0
- v2.266.1
- v2.266.1-mimalloc
- v2.266.1-jemalloc
- v2.266.0
- v2.265.0
- v2.265.0-sqlx-memory-hotfix
- v2.265.0-heaptrack-profiler-with-tini
- v2.265.0-heaptrack-profiler-prod
- v2.265.0-heaptrack-profiler
- v2.264.1
- v2.264.0
- v2.263.0
- v2.263.0-shared-test-utils
- v2.262.0
- v2.261.1
- v2.261.1-rpc-logs
- v2.261.1-orderbook-profiler-3
- v2.261.1-orderbook-profiler-2
- v2.261.1-orderbook-profiler
- v2.261.0
- v2.260.0
- v2.260.0-sqlx-update
- v2.260.0-jit-order-owners
- v2.259.0
- v2.259.0-revert-versions-with-profiler-2
- v2.259.0-revert-versions-with-profiler
- v2.259.0-revert-versions-2
- v2.259.0-revert-versions
- v2.259.0-dependencies-downgrade-2
- v2.259.0-dependencies-downgrade
- v2.258.2
- v2.258.2-temp-balances-log
- v2.258.1
- v2.258.1-temp-solvers-dto
- v2.258.0
- v2.257.1
- v2.257.0
- v2.256.0
- v2.255.1
- v2.255.1-temp-solvers
- v2.255.0
- v2.254.3
- v2.254.2
- v2.254.1
- v2.254.0
- v2.253.3
- v2.253.3-0x-playground-3
- v2.253.2
- v2.253.1
- v2.253.0
- v2.252.0
- v2.251.2
- v2.251.1
- v2.251.0
- v2.250.3
- v2.250.2
- v2.250.1
- v2.250.0
- v2.249.1
- v2.249.0
- v2.248.1
- v2.248.0
- v2.247.1
- v2.247.0
- v2.246.1
- v2.246.0
- v2.245.2
- v2.245.1
- v2.245.0
- v2.244.1
- v2.244.0
- v2.243.1
- v2.243.0
- v2.242.2
- v2.242.1
- v2.242.0
- v2.241.0
- v2.240.1
- v2.240.0
- v2.239.2-camelcase
- v2.239.1
- v2.239.1-camelcase
- v2.239.0
- v2.238.1
- v2.238.1-2171
- v2.238.1-0x-liquidity
- v2.238.0
- v2.237.1-humantime
- v2.237.0
- v2.236.1
- v2.236.0
- v2.235.1
- v2.235.0
- v2.234.0
- v2.233.0
- v2.232.0
- v2.231.1
- v2.231.0
- v2.230.1
- v2.230.0
- v2.229.2
- v2.229.1
- v2.229.0
- playground
Showing
17 changed files
with
214 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use { | ||
crate::{ | ||
domain::{ | ||
competition::{ | ||
self, | ||
score::{self, SuccessProbability}, | ||
}, | ||
eth, | ||
}, | ||
util::conv::u256::U256Ext, | ||
}, | ||
solver::settlement_rater::{ScoreCalculator, ScoringError}, | ||
}; | ||
|
||
pub fn score( | ||
score_cap: eth::U256, | ||
objective_value: eth::U256, | ||
success_probability: SuccessProbability, | ||
failure_cost: eth::U256, | ||
) -> Result<competition::Score, score::Error> { | ||
match ScoreCalculator::new(score_cap.to_big_rational()).compute_score( | ||
&objective_value.to_big_rational(), | ||
failure_cost.to_big_rational(), | ||
success_probability.0, | ||
) { | ||
Ok(score) => Ok(score.into()), | ||
Err(ScoringError::ObjectiveValueNonPositive(_)) => { | ||
Err(score::Error::ObjectiveValueNonPositive) | ||
} | ||
Err(ScoringError::ScoreHigherThanObjective(_)) => { | ||
Err(score::Error::ScoreHigherThanObjective) | ||
} | ||
Err(ScoringError::SuccessProbabilityOutOfRange(_)) => Err(score::Error::Boundary( | ||
anyhow::anyhow!("unreachable, should have been checked by solvers"), | ||
)), | ||
Err(ScoringError::InternalError(err)) => Err(score::Error::Boundary(err)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::{boundary, domain::eth}; | ||
|
||
impl Score { | ||
pub fn new( | ||
score_cap: eth::U256, | ||
objective_value: eth::U256, | ||
success_probability: SuccessProbability, | ||
failure_cost: eth::U256, | ||
) -> Result<Self, Error> { | ||
boundary::score::score( | ||
score_cap, | ||
objective_value, | ||
success_probability, | ||
failure_cost, | ||
) | ||
} | ||
} | ||
|
||
/// Represents a single value suitable for comparing/ranking solutions. | ||
/// This is a final score that is observed by the autopilot. | ||
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)] | ||
pub struct Score(pub eth::U256); | ||
|
||
impl From<Score> for eth::U256 { | ||
fn from(value: Score) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl From<eth::U256> for Score { | ||
fn from(value: eth::U256) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
/// Represents the probability that a solution will be successfully settled. | ||
#[derive(Debug, Clone)] | ||
pub struct SuccessProbability(pub f64); | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error("objective value is non-positive")] | ||
ObjectiveValueNonPositive, | ||
#[error("objective value is higher than the objective")] | ||
ScoreHigherThanObjective, | ||
#[error("invalid objective value")] | ||
Boundary(#[from] boundary::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.